Connecting Tech Pros Worldwide Help | Site Map

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

seth.m.green@gmail.com
Guest
 
Posts: n/a
#1: Dec 21 '05
<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.

McKirahan
Guest
 
Posts: n/a
#2: Dec 21 '05

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


<seth.m.green@gmail.com> wrote in message
news:1135197662.985483.223830@g49g2000cwa.googlegr oups.com...[color=blue]
> <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.
>[/color]

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/


seth.m.green@gmail.com
Guest
 
Posts: n/a
#3: Dec 21 '05

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


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.

David Dorward
Guest
 
Posts: n/a
#4: Dec 21 '05

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


seth.m.green@gmail.com wrote:
[color=blue]
> 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.[/color]

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
VK
Guest
 
Posts: n/a
#5: Dec 21 '05

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



seth.m.green@gmail.com wrote:[color=blue]
> <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.[/color]

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>

Michael Winter
Guest
 
Posts: n/a
#6: Dec 21 '05

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


On 21/12/2005 22:39, VK wrote:

[snip]
[color=blue]
> <a href="javascript:void(0)" [...][/color]

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.
RobG
Guest
 
Posts: n/a
#7: Dec 22 '05

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


seth.m.green@gmail.com wrote:[color=blue]
> <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.
>[/color]


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[color=blue]
>[/color]

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
seth.m.green@gmail.com
Guest
 
Posts: n/a
#8: Dec 22 '05

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


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).

seth.m.green@gmail.com
Guest
 
Posts: n/a
#9: Dec 22 '05

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


interesting. thanks for the working code.

Randy Webb
Guest
 
Posts: n/a
#10: Dec 22 '05

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


seth.m.green@gmail.com said the following on 12/21/2005 8:03 PM:[color=blue]
> interesting. thanks for the working code.
>[/color]

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/
VK
Guest
 
Posts: n/a
#11: Dec 22 '05

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



Michael Winter wrote:[color=blue]
> On 21/12/2005 22:39, VK wrote:[/color]
[color=blue][color=green]
> > <a href="javascript:void(0)" [...][/color]
>
> Just how many times must you be asked not to recommend rubbish like that?[/color]

? It is not *my* code, it's copy'n'paste fragment of the OP's code
where I changed a bit the part you did not quote. So you may address
your claims to OP but he already comment on it rather clearly in his
2nd post (see the thread). You may try once over again though - with
*him*.

P.S. On your leisure time google for keyword "bookmarklet". Also may
try "bookmarklet site:mozilla.org"
Then the buttle is lost - it's lost. That never was *my buttle* but my
sincere condolescence anyway.

bwucke@gmail.com
Guest
 
Posts: n/a
#12: Dec 22 '05

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


My simple theory:
OnClick the window.location changes to "/foo.bar?one=false&two=true"
Then milliseconds later, way before the connection could be made, it
changes again, to "javascript: void(0);"

First,
onClick="window.location.href='/foo.bar?one=false&two=true';return
false"
This prevents default action from being performed (supposedly).
Then, href="#" instead of href="javascript:void(0)". A link that moves
you to current location within page, essentially doing nothing, not
even reloading the page. Sideeffect: # gets appended to URL. Not a big
deal. Three. I often use Lynx. I hate you.

VK
Guest
 
Posts: n/a
#13: Dec 22 '05

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



seth.m.green@gmail.com wrote:[color=blue]
> 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).[/color]

IE is a closed source browser so whatever is not documented is forcely
a subject of speculations. Here's another one: it may be a navigation
request priority issue.
"onclick" expression processed before href havigation. So in case like:
<a href="go here" onclick="go there">
there are two navigation requests pending. IE gives the priority to the
"official" request from href (even if it doesn't lead anywhere). FF
gives the priority to whoever asked first (onclick) - or it's so smart
that it looks at href and sees that there is not any actual navigation
in href. The latter could be checked by studying Firefox source code,
the first will remain a speculation.

Michael Winter
Guest
 
Posts: n/a
#14: Dec 22 '05

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


On 22/12/2005 08:53, VK wrote:
[color=blue]
> Michael Winter wrote:
>[color=green]
>> On 21/12/2005 22:39, VK wrote:
>>[color=darkred]
>>> <a href="javascript:void(0)" [...][/color]
>>
>> Just how many times must you be asked not to recommend rubbish like
>> that?[/color]
>
> ? It is not *my* code [...][/color]

The moment you post a suggestion for someone to use, that /is/ your code
and you are responsible for it. If you think that something is a bad
idea, then don't recommend it.

An alternate approach that may be workable for the OP is to submit a
form, styling the submit button like a link (if necessary).

[snip]
[color=blue]
> P.S. On your leisure time google for keyword "bookmarklet". Also may
> try "bookmarklet site:mozilla.org"[/color]

What on Earth do bookmarklets have to do with using the javascript
pseudo-scheme in links?

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
VK
Guest
 
Posts: n/a
#15: Dec 22 '05

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



Michael Winter wrote:[color=blue]
> On 22/12/2005 08:53, VK wrote:
>[color=green]
> > Michael Winter wrote:[/color]
> The moment you post a suggestion for someone to use, that /is/ your code
> and you are responsible for it.[/color]

One becomes responsible for someone code as soon as she quoted it?
That's a newsgroup rule I was not aware of. Any link to read more?
;-)
[color=blue]
> What on Earth do bookmarklets have to do with using the javascript
> pseudo-scheme in links?[/color]

Not "bookmarks" - *bookmarklets*
This is a very popular and fast growing scripting technics totally
ignored so far in clj, but fully endorsed by all browser producers
including Firefox. Their core functionality based on <a
href="javascript:code"> usage. Just google a bit.

As a consolation I can tell that you're winning the buttle over
"<script type" instead of "<script language".

50/50 result is not bad at all.

Michael Winter
Guest
 
Posts: n/a
#16: Dec 22 '05

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


On 22/12/2005 12:45, VK wrote:

[snip]
[color=blue]
> One becomes responsible for someone code as soon as she quoted it?[/color]

You didn't quote the code, you supplied it as a 'solution'. That it was
mainly the OP's code is immaterial: you still posted it as /your/ advice.

[snip]
[color=blue][color=green]
>> What on Earth do bookmarklets have to do with using the javascript
>> pseudo-scheme in links?[/color]
>
> Not "bookmarks" - *bookmarklets*[/color]

You really should learn to read, VK. Bookmarklets use the javascript
pseudo-scheme. Links should not.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
VK
Guest
 
Posts: n/a
#17: Dec 22 '05

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



Michael Winter wrote:[color=blue]
> You really should learn to read, VK. Bookmarklets use the javascript
> pseudo-scheme. Links should not.[/color]

How do think bookmarlets are being displayed on the page? :-0
<a href="javascript:code">Bookmark this util</a>

Unless we're going to introduce a refined mental distinction between:
<a href="javascript:code">Read RSS feed</a>
// bad use
and
<a href="javascript:code">Bookmark to read RSS feed</a>
// good use

And what if someone used first <a href="javascript:code">Read RSS
feed</a> to read the feed and later added it to bookmarks? Was it bad
use which became good one at the moment of transfering to her bookmark
collection?
As I said: if the buttle is over - it's over.

VK
Guest
 
Posts: n/a
#18: Dec 22 '05

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



VK wrote:[color=blue]
> How do think bookmarlets are being displayed on the page? :-0
> <a href="javascript:code">Bookmark this util</a>[/color]

To stay completely within the *link* issue let's talk about so popular
"ever fresh" links:

<a href="javascript:
var d = new Date();
var u = ''+d.getFullYear()+d.getMonth()+d.getDay();
window.location.href = 'http://www.myserver.com/'
+ u + '.html';
">Bookmark my webcam</a>

VK
Guest
 
Posts: n/a
#19: Dec 22 '05

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



Lee wrote:[color=blue]
> The use of the javascript: pseudo-protocol for its side-effect
> should be avoided when there is a better alternative.
> In the case of bookmarklets, there is no better alternative.
> That's the distinction.[/color]

So shall be it!

At least newcomers may use a bulletproof protection against the initial
beatdown: just say "my bookmarklet doesn't work as expected" - do not
say "my link". :-)

Closed Thread