Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > void(0) is disabling my onclick event (ie only) ???

Reply
Thread Tools

void(0) is disabling my onclick event (ie only) ???

 
 
seth.m.green@gmail.com
Guest
Posts: n/a
 
      12-21-2005
<a href="javascript: void(0);"
onclick="window.location.href='/foo.bar?one=false&two=true'">Link</a>

works like a charm in Firefox. I get NOTHING in IE. but if I replace
the javascript: void(0) with just a #, then it works in IE. wtf? Any
help.

 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      12-21-2005
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> <a href="javascript: void(0);"
> onclick="window.location.href='/foo.bar?one=false&two=true'">Link</a>
>
> works like a charm in Firefox. I get NOTHING in IE. but if I replace
> the javascript: void(0) with just a #, then it works in IE. wtf? Any
> help.
>


Isn't what you're doing the same as the following?

<a href="/foo.bar?one=false&two=true">Link</a>


Or maybe these links will help:

"So, when you want to place an onclick handler on an anchor tag, ..."
http://www.themaninblue.com/writing/...ve/2004/08/05/

Anchors and Links
"If you supply a value for the ONCLICK attribute,
the specified action overrides the default link behavior."
http://devedge-temp.mozilla.org/libr...ide/tags7.html

Javascript Best Practices
Using onClick in <A> tags
http://www.mattkruse.com/javascript/bestpractices/


 
Reply With Quote
 
 
 
 
seth.m.green@gmail.com
Guest
Posts: n/a
 
      12-21-2005
yes, it is the same as just putting the url in the href attribute, but
I don;t want bots to follow the link, so I am having javascript perform
the redirect. I appreciate the links you mention but none of them
explain the behavior I am seeing. I'm not so much interested in other
techniques, instead I am interested in understanding why the code I
have written doesn't function in IE.

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      12-21-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> yes, it is the same as just putting the url in the href attribute, but
> I don;t want bots to follow the link, so I am having javascript perform
> the redirect.


Not a great idea ...

1 - Not every member of the group of user agents "not bots" supports
JavaScript

2 - Not every member of the group of user agents "not bots that support
JavaScript" has JavaScript turned on

and the biggy ...

3 - Not every member of the group of user agents "bots" does not support
JavaScript.

I've got a nice little bot (Pavuk) which supports JavaScript.

Just use robots.txt to ask bots to keep away from those URLs.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      12-21-2005

(E-Mail Removed) wrote:
> <a href="javascript: void(0);"
> onclick="window.location.href='/foo.bar?one=false&two=true'">Link</a>
>
> works like a charm in Firefox. I get NOTHING in IE. but if I replace
> the javascript: void(0) with just a #, then it works in IE. wtf? Any
> help.


There is no technical reasons for that. Must be some security patch or
a side effect of some security patch. Use instead:

<a href="javascript:void(0)"

onclick="setTimeout('window.location.href=\'/foo.bar?one=false&two=true\';')">Link</a>

 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      12-21-2005
On 21/12/2005 22:39, VK wrote:

[snip]

> <a href="javascript:void(0)" [...]


Just how many times must you be asked not to recommend rubbish like that?

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      12-22-2005
(E-Mail Removed) wrote:
> <a href="javascript: void(0);"
> onclick="window.location.href='/foo.bar?one=false&two=true'">Link</a>
>
> works like a charm in Firefox. I get NOTHING in IE. but if I replace
> the javascript: void(0) with just a #, then it works in IE. wtf? Any
> help.
>



This from a recent Richard Cornford post seems appropriate:

"IE treats the activation of a javascript pseudo-protocol HREF as
navigation, and when used the browser goes into a 'waiting state'
pending the arrival of a replacement for the content. In this
state many previously available browser facilities are withdrawn,
including GIF animation and image swapping.

"The normal strategy for dealing with this issue is to never use a
javascript pseudo-protocol HREF that will not result in the
replacement of the contents of the current page (so never to execute
a function for its side effect).

"Usually the same effect as a javascript pseudo-protocol HREF can be
achieved (without the detrimental consequences in IE) with a suitably
default action cancelling intrinsic event handler. An onclick
handlers are the usual replacement."

<URL:
http://groups.google.com/group/comp....05d2132efcf609
>


So the solution is:

<a href="whyLinkDidntWork.html"
onclick="window.location.href='/foo.bar?one=false&two=true'">Link</a>

Bots (if they're not smart enough to follow the onclick) will get the
same text page that users sans JS get.


--
Rob
 
Reply With Quote
 
seth.m.green@gmail.com
Guest
Posts: n/a
 
      12-22-2005
Yes, I understand all of that, and while I also understand your
compulsion to teach best practices I know exactly what I am getting
myself into. My #1 solution to my problem would have been to use a
robots.txt file but you can scratch that because

1. Not every bot adheres to robots.txt rules

I have a very special case in which I need to do this. And while I too
have been accused of "preaching" standards, and while I was practiciing
"unobtrusive javascript" a long time ago, this is what I want to do
know. I'm a big boy.

Even if I didn't want to put this into practice, I would have asked the
same question for academic reasons. It seems that no one can explain
this behavior other than speculated it is a bug in some security patch
(or something of that ilk).

 
Reply With Quote
 
seth.m.green@gmail.com
Guest
Posts: n/a
 
      12-22-2005
interesting. thanks for the working code.

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      12-22-2005
(E-Mail Removed) said the following on 12/21/2005 8:03 PM:
> interesting. thanks for the working code.
>


Too bad it doesn't really "work" though.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling onclick (using Spry) Steve Javascript 6 12-22-2006 12:22 AM
Problem w/ disabling buttons after onclick on clientside Michael Groeger ASP .Net 2 01-20-2006 01:18 PM
how to handle both onmouseup event and onClick event JerryG ASP .Net 0 12-20-2005 03:49 AM
button.onclick = new Function("func2()") + button.onclick foldface@yahoo.co.uk Javascript 2 09-26-2005 08:13 AM
document.onclick=doIt() same as document.onclick=doIt ? bob Javascript 3 08-21-2003 12:14 PM



Advertisments