[thelist] href=# versus href=JavaScript.....
Aylard JA (James)
jaylard at equilon.com
Thu Feb 22 14:19:14 CST 2001
Tab,
> I know there's no shortage of pennies here, but I too have had cases where
> href="javascript: ..." didn't work, but href="#" onclick="..." did work.
I
> haven't discerned the pattern, so my solution is to try href="javascript"
> first, and if it doesn't work, switch to href="#".
One ill side-effect that can occur when using the javascript:
protocol within the href when opening a new window is that the opener window
will in some browsers redirect to an otherwise blank page except for the
word "[object]" (IE) or "[object Window]" (Netscape 4.x). However, assigning
the window.open method to a variable avoids this. So:
<a href="javascript: window.open();">
will redirect the opener to [object] or [object Window]
<a href="javascript: var newWin = window.open();">
will pop the window without an opener redirect
However, I still *strongly* advocate placing the target URI in the
href attribute (like a normal link) and placing the javascript in an onclick
event handler (with the addition of "return false" at the end to cancel the
link's default behavior).
* Benefit of this approach stated previously: older and non-JS-enabled
browsers will still open the link, just without all of the classy chrome
modifications.
* Benefit of this approach *not* stated previously: religious shift-clickers
(i.e., those who open links in a new window) will still open the target
document in a new window without error. Try that with the javascript in the
href...
James Aylard
More information about the thelist
mailing list