473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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

Dec 21 '05 #1
18 7403
<se**********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr 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/
Dec 21 '05 #2
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.

Dec 21 '05 #3
se**********@gmail.com 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
Dec 21 '05 #4
VK

se**********@gmail.com 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>

Dec 21 '05 #5
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.
Dec 21 '05 #6
se**********@gmail.com 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
Dec 22 '05 #7
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).

Dec 22 '05 #8
interesting. thanks for the working code.

Dec 22 '05 #9
se**********@gmail.com 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/
Dec 22 '05 #10
VK

Michael Winter wrote:
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.

Dec 22 '05 #11
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.

Dec 22 '05 #12
VK

se**********@gmail.com wrote:
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.

Dec 22 '05 #13
On 22/12/2005 08:53, VK wrote:
Michael Winter wrote:
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 [...]


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

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 22 '05 #14
VK

Michael Winter wrote:
On 22/12/2005 08:53, VK wrote:
Michael Winter wrote: 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.

Dec 22 '05 #15
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]
What on Earth do bookmarklets have to do with using the javascript
pseudo-scheme in links?


Not "bookmarks" - *bookmarklets*


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.
Dec 22 '05 #16
VK

Michael Winter wrote:
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.

Dec 22 '05 #17
VK

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

Dec 22 '05 #18
VK

Lee wrote:
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.


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

Dec 22 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andreas Knollmann | last post by:
Hi, I create an object like this: var cell = document.createElement("td"). It doesn't have to be cell. I want this cell to use the onclick event. What doesn't work in the IE as well as with...
17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
2
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick...
17
by: abs | last post by:
My element: <span onclick="alert('test')" id="mySpan">test</span> Let's say that I don't know what is in this span's onclick event. Is it possible to add another action to this element's onclick...
5
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below...
5
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
3
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick...
6
by: Nathan Sokalski | last post by:
I have a DataList which contains several LinkButtons, which are used to select a category in my application. I want the currently selected category to use a different CSS class. Here is an example...
2
by: DavidGeorge | last post by:
In an earlier thread I recounted a problem I was having, but it took a while to reduce the problem to it's basic components and the issue became somewhat confused in reaching that point. I hope you...
4
by: bbobely | last post by:
I have a generic subform control (subMain) whose sourceobject changes based on a combobox selection. Each sourceobject is a separate subform. These subforms (subsub1, subsub2 etc) have a field whose...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.