[thelist] href=# versus href=JavaScript.....

Tab Alleman talleman at autobex.com
Thu Feb 22 14:32:15 CST 2001


That's good stuff, and so is the href="javascript:" onclick="..."

The only thing is I would swear that sometimes the javascript in the href
has bombed on things other than opening pop-ups.. things like self.close(),
for instance.  But I could be wrong.. my memory has been sprouting leaks of
late, after all..

anh.  Whatever.. I'll try both of those tips next time I encounter the
problem!

Tab


-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Aylard JA (James)
Sent: Thursday, February 22, 2001 2:25 PM
To: 'thelist at lists.evolt.org'
Subject: RE: [thelist] href=# versus href=JavaScript.....


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

---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list