Forum Moderators: open

Message Too Old, No Replies

javascript:location.href - PROBLEMS, Please Help

Need Script to open in a "new" window ...

         

roberthilley

10:47 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



I am having a problem getting this code to work how I'd like ... as it is setup now, it opens in the smae window. I would like to have it open in a new window, i.e. target="_blank" but the target idea does not work.

Does anybody know how to modify the snippet below to make it open in a new window?

<a href="javascript:location.href='http://www.example.com/bookmark.php?wt=nw&pub=schmidtandclark&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)">Social Bookmarking</a>

[edited by: encyclo at 2:35 am (utc) on April 4, 2007]
[edit reason] examplified, see terms of service [/edit]

Dabrowski

10:59 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are using the wrong method:


javascript:location.href='http://www.example.com/bookmark.php?wt=nw&pub=schmidtandclark&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)

location.href referrs to the current page, use window.open instead:


javascript:window.open( 'http://www.example.com/bookmark.php?wt=nw&pub=schmidtandclark&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title))

and add target='_blank' to the A tag. You will get a popup warning of course.

[edited by: encyclo at 2:36 am (utc) on April 4, 2007]
[edit reason] see above [/edit]

roberthilley

11:49 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



Dabrowski ... thanks man! I am really grateful ... I have been racking mt brain about this all day long and am having serious problems. I just posted another topic here: [webmasterworld.com...]

Dabrowski

10:28 am on Apr 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You still haven't got it quite right, change the href to # on your A tag or the current page will also change!

kaled

10:34 am on Apr 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't need javascript...

<a href="newpage.html" target="_blank">click here</a>

In most cases, this will avoid problems with popup-blockers too.

Kaled.

Dabrowski

11:35 am on Apr 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good point Kaled, whoa, can't believe I missed that!