Please don't spawn popup-windows like this:
or this:
rather, use:
benefits:
- statusbar still indicates where you're going
- non-js users (and search-engines) still end up at the correct page
- current page doesn't jump to top (faux-anchor '#' evil)
- shift- and right-click options still open the correct page
Update:
Apparently using
<a href="javascript:window.open('foo.html');">or this:
<a href="#" onclick="window.open('foo.html');">rather, use:
<a href="foo.html" onclick="window.open(this.href);return false;">benefits:
- statusbar still indicates where you're going
- non-js users (and search-engines) still end up at the correct page
- current page doesn't jump to top (faux-anchor '#' evil)
- shift- and right-click options still open the correct page
Update:
Apparently using
return false; in the href can mess up some browser's popup-blocking, so watch out if you care about that (haven't noticed it myself, but then again, I almost never use popups). [via]comments
1. posted by Marza at 00:56 on August 14, 2001
Goede tip, meteen gewijzigd. Ik stoorde me al aan het niet met de rechtermuisknop kunnen klikken.
2. posted by David at 11:16 on August 14, 2001
Dit zocht ik. Bedankt!
3. posted by pup at 17:18 on August 14, 2001
excellent tip. i was looking for a nice backwards compatible way of doing this.
4. posted by Jim at 17:55 on December 28, 2001
great tip, i too was looking for something that would work with js turned off.
5. posted by Joe Clark at 21:40 on December 30, 2001
Yeah, except you have to duplicate mouse functions with keyboard functions for accessibility. It's onkeyDown, I think, but I'm not an expert at this. Keep all the onClick stuff-- just add the keyboard support.
6. posted by Norse at 21:57 on January 02, 2002
Het niet ik been zocht dit ik ik de met wheerholdenit.
7. posted by charles at 22:39 on January 04, 2002
How do I also add the no-address/ noscroll and other elements to that tag?
8. posted by matt at 18:01 on February 17, 2002
If you're just opening a new window with out specifying any properties (window size etc.) then you should really be using TARGET="_blank" instead of an onClick. That way even people with javascript turned of will get a new window.
9. posted by zachariah at 06:42 on March 21, 2002
matt - target="_blank" is not vaild xhtml which is the current verion of html
10. posted by Tim Scarfe at 21:39 on June 16, 2002
Great Tip.
I don't like inline behaviour in the HTML element of my documents though, How about making it have a class of "pop", and then having a seperate script run through the document at the end picking up all the elements and assigning the events?
De-gradable coding, isn't it so cool :)
I don't like inline behaviour in the HTML element of my documents though, How about making it have a class of "pop", and then having a seperate script run through the document at the end picking up all the elements and assigning the events?
De-gradable coding, isn't it so cool :)
11. posted by kesor at 23:24 on August 31, 2002
the return false; thingy doesnt quite work in opera (tested with 6.04).
I tried to expand text, like this :
<p>this is some text <a href="" onclick="moretext.style.display='inline'; return false;">more text</a></p>
<p id="moretext">this is some more text</p>
It works great in explorer, but doesnt work in opera and mozilla.
I guess its the return false that is not working.
I tried to expand text, like this :
<p>this is some text <a href="" onclick="moretext.style.display='inline'; return false;">more text</a></p>
<p id="moretext">this is some more text</p>
It works great in explorer, but doesnt work in opera and mozilla.
I guess its the return false that is not working.
12. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
try
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
13. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
try
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
14. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
try
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
15. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
try
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
16. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
try
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
17. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
try
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
18. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
try
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
19. posted by 127.0.0.1,me,sh0rtie at 13:13 on September 04, 2002
try
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
<a href="" onclick="document.getElementById('moretext').style.display='inline';return false">blah</a>
20. posted by 127.0.0.1,me,sh0rtie at 13:16 on September 04, 2002
holy multiple posting batman
sorry about that , blame mozilla , i only hit submit once :/
sorry about that , blame mozilla , i only hit submit once :/
21. posted by MidgetSniper at 01:13 on September 19, 2002
Thank you for the info. I've been trying for 3 days now to get the page to stop refreshing everytime I wanted to post a comment. I'm in process of building this site and that was a tremendous help.
22. posted by xxx.lt,akello,Akello at 03:51 on December 23, 2002
me@127.0.0.1's way doesn't work either :(
23. posted by gfdh at 11:39 on February 20, 2003
ghgf
24. posted by FitzChivalry at 13:13 on September 17, 2003
I'm so glad that googling on "href onclick" led me to this site!
25. posted by yahoo.com,redjester,hadlock at 19:41 on October 12, 2003
hi how do you open this pop-up in a set size window?
26. posted by Gobalopper at 11:40 on November 02, 2003
Try this hadlock:
<a href="yourlink.html" onclick="window.open(this.href,'blah','height=250,width=300,top=50,left=50,scrollbars=yes,titlebar=true'); return false;">link text</a>
<a href="yourlink.html" onclick="window.open(this.href,'blah','height=250,width=300,top=50,left=50,scrollbars=yes,titlebar=true'); return false;">link text</a>
27. posted by Ich at 15:44 on December 30, 2003
Fuck you
28. posted by nyexotic at 21:55 on January 29, 2004
I want to make a pop up for my website with a picture as soon as they open my site & another when people turn on their computer. If someone can e-mail me a script that would be awesome. thanks.....
29. posted by earl-ku at 13:41 on February 09, 2004
thanks thanks thanks
30. posted by Jay at 06:35 on March 10, 2004
Great tip. Exactly what I needed. Thanks!
31. posted by wooki at 21:38 on April 03, 2004
what. when people turn on their computer?
32. posted by fargo at 23:16 on May 11, 2004
Does not seem to work for me (tested in Mozilla Firefox and Opera 6.12). It opens the new window but also the current window jumps to the url present between the quotes in href="".
33. posted by milov at 23:22 on May 11, 2004
Really? Even with the "return false;" at the end?
34. posted by Symen at 09:07 on December 01, 2004
>fargo
It works in my firefox, opera and ie. You must have made a typo..
But anyway, good article milovrs!
It works in my firefox, opera and ie. You must have made a typo..
But anyway, good article milovrs!
35. posted by sandra at 12:39 on July 01, 2005
Thanks gobalopper! this helped me great!!
36. posted by Joy at 01:41 on September 22, 2005
How can I use window.open(this.href...
with frames? I have the <a href="offer.html".. in a frame and when i click it, offer.html is open in the self frame and not in a popup window.
with frames? I have the <a href="offer.html".. in a frame and when i click it, offer.html is open in the self frame and not in a popup window.
37. posted by gmail.com,askubusku,seema at 12:28 on September 27, 2005
<p>this is some text <a href="" onclick="moretext.style.display='inline'; return false;">more text</a></p>
<p id="moretext">this is some more text</p>
It works great in explorer, but doesnt work in opera and mozilla.
I guess its the return false that is not working.
<p id="moretext">this is some more text</p>
It works great in explorer, but doesnt work in opera and mozilla.
I guess its the return false that is not working.
38. posted by Milo at 12:30 on September 27, 2005
Nope, you just need to access moretext via the getElementById-function, like so:
onclick="document.getElementById('moretext').style.display='inline'; return false;"
This should work in IE, Mozilla and Opera.
onclick="document.getElementById('moretext').style.display='inline'; return false;"
This should work in IE, Mozilla and Opera.
39. posted by eapen at 21:59 on October 25, 2005
doesnt work for me either in firefox. it probably has to do with one of my extensions, but its a pain to go through each one.
40. posted by mayglee at 08:02 on November 11, 2005
how to make a popup onclick with style, with background image and so on?
good page, thanx
good page, thanx
41. posted by riccardo at 03:06 on November 12, 2005
how about the same thing with forms?
42. posted by hotremoveforsendingmail.com,sager_svend,eSKape at 08:35 on February 09, 2006
#36 Joy
I guess the only way to open links in another frame is to use targets. But target is okay, they are XHTML.. but not Strict. Maybe you are not using the right DTD? You are using framesets, so you should use XHTML Frameset.
As http://www.w3schools.com/tags/tag_a.asp say,
I guess the only way to open links in another frame is to use targets. But target is okay, they are XHTML.. but not Strict. Maybe you are not using the right DTD? You are using framesets, so you should use XHTML Frameset.
As http://www.w3schools.com/tags/tag_a.asp say,
43. posted by hotremoveforsendingmail.com,sager_svend,eSKape at 08:37 on February 09, 2006
.. (continuing) ..
As url say, target is allowed in Transitional and Frameset, but not in Strict.
As url say, target is allowed in Transitional and Frameset, but not in Strict.
44. posted by yahoo.com,fuckthegovernment,Alex at 21:56 on February 26, 2006
.^..^.
<0><0>
..<>
((SWEET))
<0><0>
..<>
((SWEET))
45. posted by RskpsVVMSlXGDP at 15:58 on June 05, 2008
tickets_5.txt;2;2
46. posted by someOne at 16:57 on January 08, 2009
like i didnt know that allready :/
47. posted by Imu at 13:58 on November 10, 2009
This is great, I use this to open 40 000 porn pop-ups at all my clients computers. Thank you!