Please don't spawn popup-windows like this:
<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]
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 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.
<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>
<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>
<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>
<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>
sorry about that , blame mozilla , i only hit submit once :/
<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>
It works in my firefox, opera and ie. You must have made a typo..
But anyway, good article milovrs!
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.
<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.
onclick="document.getElementById('moretext').style.display='inline'; return false;"
This should work in IE, Mozilla and Opera.
good page, thanx
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,
As url say, target is allowed in Transitional and Frameset, but not in Strict.
<0><0>
..<>
((SWEET))