PDA

View Full Version : Not working?



dkblackhawk
02-17-2014, 11:15 PM
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 :D


javascript:(function(){ window.open('http://sitename.com?title='+encodeURIComponent(location.href);&url='+encodeURIComponent(location.href)); })();

When I click on the bookmark, nothing happens.

traq
02-18-2014, 12:33 AM
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.
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.


(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).


Also is it possible to grab the title of the current page in javascript? Thanks :D
Assuming there is a <title> tag, and that the first one is the correct one:

var title = document.getElementsByTagName("title")[0].innerHTML;