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

S

seth.m.green

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

McKirahan

<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/perspective/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/library/manuals/1998/htmlguide/tags7.html

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

seth.m.green

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

David Dorward

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

VK

<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>
 
M

Michael Winter

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
 
R

RobG

<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...ity,+img+elements+dissappear#ed05d2132efcf609
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.
 
S

seth.m.green

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

VK

Michael said:
On 21/12/2005 22:39, VK wrote:
<a href="javascript:void(0)" [...]

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

? 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.
 
B

bwucke

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

VK

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

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

Lee

(e-mail address removed) said:
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).

There's no bug involved.

You've given the browser contradictory instructions. You've got
an onclick handler that changes location but doesn't return false.
That's a coding mistake.

If you write code that says, in effect, "do something unpredictable",
you shouldn't be surprised to find that you can't predict how it
will behave.
 
M

Michael Winter

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

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

? It is not *my* code [...]

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]
P.S. On your leisure time google for keyword "bookmarklet". Also may
try "bookmarklet site:mozilla.org"

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

[snip]

Mike
 
V

VK

Michael said:
The moment you post a suggestion for someone to use, that /is/ your code
and you are responsible for it.

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?
;-)
What on Earth do bookmarklets have to do with using the javascript
pseudo-scheme in links?

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

Michael Winter

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

[snip]
One becomes responsible for someone code as soon as she quoted it?

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]
Not "bookmarks" - *bookmarklets*

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

[snip]

Mike
 
V

VK

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

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

VK

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

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>
 
L

Lee

VK said:
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


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top