Results 1 to 2 of 2

Thread: Not working?

  1. #1
    Join Date
    Sep 2008
    Posts
    44
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Not working?

    I can't seem to grasp why this isn't working right now...I am using it as a tab in Chrome to open in a new window and fill in the forms. Also is it possible to grab the title of the current page in javascript? Thanks

    Code:
    javascript:(function(){ window.open('http://sitename.com?title='+encodeURIComponent(location.href);&url='+encodeURIComponent(location.href)); })();
    When I click on the bookmark, nothing happens.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by dkblackhawk View Post
    I can't seem to grasp why this isn't working right now...I am using it as a tab in Chrome to open in a new window and fill in the forms.
    Code:
    javascript:(function(){ window.open('http://sitename.com?title='+encodeURIComponent(location.href);&url='+encodeURIComponent(location.href)); })();
    When I click on the bookmark, nothing happens.
    You have syntax errors. You can use a console (press [F12] in most browsers) to find this sort of thing. Decent code editors will also have syntax highlighting that makes simple mistakes like this obvious.

    In this case,
    • you have an extra semicolon after you urlencode the location.href,
    • you don't concatenate the second and third strings, and
    • you forgot the opening quote for the third string.


    Code:
    (function(){ window.open( 'http://sitename.com?title=' +encodeURIComponent( location.href )+ '&url=' +encodeURIComponent( location.href ) ); })()
    Tested; works (though it's likely your browser's popup blocker will, well, block it).

    Quote Originally Posted by dkblackhawk View Post
    Also is it possible to grab the title of the current page in javascript? Thanks
    Assuming there is a <title> tag, and that the first one is the correct one:
    Code:
    var title = document.getElementsByTagName("title")[0].innerHTML;

Similar Threads

  1. Replies: 8
    Last Post: 12-16-2013, 07:37 PM
  2. Replies: 8
    Last Post: 11-23-2009, 04:00 AM
  3. Replies: 4
    Last Post: 10-24-2009, 07:07 AM
  4. javascript code not working in ie but working in firefox
    By sukanya.paul in forum JavaScript
    Replies: 2
    Last Post: 02-20-2009, 01:44 PM
  5. Replies: 1
    Last Post: 08-21-2008, 02:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •