Connecting Tech Pros Worldwide Forums | Help | Site Map

IE6 Ignores JavaScript's return false on a Link

vunet.us@gmail.com
Guest
 
Posts: n/a
#1: Apr 17 '07
Why does IE6 ignores JavaScript's return false on a link and how to
fix it? Firefox works perfect!

<a href="page1.html" onclick="return test(this)">Test</a>

JS:

function test(obj)
{
if(obj.href=='page1.html'){
doSomething();
return false;
}else{
return true;
}
}


Randy Webb
Guest
 
Posts: n/a
#2: Apr 17 '07

re: IE6 Ignores JavaScript's return false on a Link


vunet.us@gmail.com said the following on 4/17/2007 12:29 PM:
Quote:
Why does IE6 ignores JavaScript's return false on a link and how to
fix it? Firefox works perfect!
IE isn't ignoring the return false, it is returning true. The href
property is an absolute path in IE (test it with an alert).
Quote:
<a href="page1.html" onclick="return test(this)">Test</a>
>
JS:
>
function test(obj)
{
alert(obj.href)

And you will see that the href property isn't what you expect it to be.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
vunet.us@gmail.com
Guest
 
Posts: n/a
#3: Apr 17 '07

re: IE6 Ignores JavaScript's return false on a Link


On Apr 17, 12:41 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Quote:
vunet...@gmail.com said the following on 4/17/2007 12:29 PM:
>
Quote:
Why does IE6 ignores JavaScript's return false on a link and how to
fix it? Firefox works perfect!
>
IE isn't ignoring the return false, it is returning true. The href
property is an absolute path in IE (test it with an alert).
>
Quote:
<a href="page1.html" onclick="return test(this)">Test</a>
>
Quote:
JS:
>
Quote:
function test(obj)
{
>
alert(obj.href)
>
And you will see that the href property isn't what you expect it to be.
>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
Sorry, I meant this does not work:

function doSomething(){
alert('no go');
}

function test(obj)
{
if(obj.href.toString().indexOf("page1.html")!= -1){
doSomething();
return false;
}else{
return true;
}
}

Randy Webb
Guest
 
Posts: n/a
#4: Apr 17 '07

re: IE6 Ignores JavaScript's return false on a Link


vunet.us@gmail.com said the following on 4/17/2007 3:18 PM:
Quote:
On Apr 17, 12:41 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Quote:
>vunet...@gmail.com said the following on 4/17/2007 12:29 PM:
>>
Quote:
>>Why does IE6 ignores JavaScript's return false on a link and how to
>>fix it? Firefox works perfect!
>IE isn't ignoring the return false, it is returning true. The href
>property is an absolute path in IE (test it with an alert).
>>
Quote:
>><a href="page1.html" onclick="return test(this)">Test</a>
>>JS:
>>function test(obj)
>>{
>alert(obj.href)
>>
>And you will see that the href property isn't what you expect it to be.
<another useless quoted signature snipped>
Quote:
Sorry, I meant this does not work:
Define "does not work" as I get the alert and the URL is not followed
with a copy/paste of your code. So you must have something else
(probably in the real doSomething()) that is causing it to break.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
vunet.us@gmail.com
Guest
 
Posts: n/a
#5: Apr 17 '07

re: IE6 Ignores JavaScript's return false on a Link


On Apr 17, 6:00 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Quote:
vunet...@gmail.com said the following on 4/17/2007 3:18 PM:
>
Quote:
On Apr 17, 12:41 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Quote:
vunet...@gmail.com said the following on 4/17/2007 12:29 PM:
>
Quote:
Quote:
>Why does IE6 ignores JavaScript's return false on a link and how to
>fix it? Firefox works perfect!
IE isn't ignoring the return false, it is returning true. The href
property is an absolute path in IE (test it with an alert).
>
Quote:
Quote:
><a href="page1.html" onclick="return test(this)">Test</a>
>JS:
>function test(obj)
>{
alert(obj.href)
>
Quote:
Quote:
And you will see that the href property isn't what you expect it to be.
>
<another useless quoted signature snipped>
>
Quote:
Sorry, I meant this does not work:
>
Define "does not work" as I get the alert and the URL is not followed
with a copy/paste of your code. So you must have something else
(probably in the real doSomething()) that is causing it to break.
>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
I will test doSomething(), thanks. But the strange this is that it
works with FF, not IE6. I did not test IE7 or other browsers yet.

Lee
Guest
 
Posts: n/a
#6: Apr 17 '07

re: IE6 Ignores JavaScript's return false on a Link


vunet.us@gmail.com said:

Quote:
>Sorry, I meant this does not work:
>
>function doSomething(){
>alert('no go');
>}
>
>function test(obj)
>{
if(obj.href.toString().indexOf("page1.html")!= -1){
doSomething();
return false;
}else{
return true;
}
>}
Have you even considered alerting the value of obj.href before deciding that the
browser doesn't work?


--

vunet.us@gmail.com
Guest
 
Posts: n/a
#7: Apr 18 '07

re: IE6 Ignores JavaScript's return false on a Link


On Apr 17, 6:13 pm, Lee <REM0VElbspamt...@cox.netwrote:
Quote:
vunet...@gmail.com said:
>
Quote:
Sorry, I meant this does not work:
>
Quote:
function doSomething(){
alert('no go');
}
>
Quote:
function test(obj)
{
if(obj.href.toString().indexOf("page1.html")!= -1){
doSomething();
return false;
}else{
return true;
}
}
>
Have you even considered alerting the value of obj.href before deciding that the
browser doesn't work?
>
--
I have a test case which shows that this function above works in IE6
if used apart from the whole page. Within a page, it does not work and
follows the link (when it shouldn't). I did not have a deeper look yet
but will work on that shortly. Perhaps, in a meantime, anyone may have
any suggestions for this approach: how effective it is and,
considering all other facts, what other alternative may exist.
Thanks.

Lee
Guest
 
Posts: n/a
#8: Apr 18 '07

re: IE6 Ignores JavaScript's return false on a Link


vunet.us@gmail.com said:
Quote:
>
>On Apr 17, 6:13 pm, Lee <REM0VElbspamt...@cox.netwrote:
Quote:
>vunet...@gmail.com said:
>>
Quote:
>Sorry, I meant this does not work:
>>
Quote:
>function doSomething(){
>alert('no go');
>}
>>
Quote:
>function test(obj)
>{
if(obj.href.toString().indexOf("page1.html")!= -1){
doSomething();
return false;
}else{
return true;
}
>}
>>
>>Have you even considered alerting the value of obj.href before deciding that the
>browser doesn't work?
>>
>--
>
>I have a test case which shows that this function above works in IE6
>if used apart from the whole page. Within a page, it does not work and
>follows the link (when it shouldn't). I did not have a deeper look yet
>but will work on that shortly. Perhaps, in a meantime, anyone may have
>any suggestions for this approach: how effective it is and,
>considering all other facts, what other alternative may exist.
The approach is fine. Either the value of obj.href is not what you
expect, or your doSomething() function contains errors.


--

vunet.us@gmail.com
Guest
 
Posts: n/a
#9: Apr 19 '07

re: IE6 Ignores JavaScript's return false on a Link


On Apr 18, 9:48 am, Lee <REM0VElbspamt...@cox.netwrote:
Quote:
vunet...@gmail.com said:
>
>
>
>
>
Quote:
On Apr 17, 6:13 pm, Lee <REM0VElbspamt...@cox.netwrote:
Quote:
vunet...@gmail.com said:
>
Quote:
Quote:
Sorry, I meant this does not work:
>
Quote:
Quote:
function doSomething(){
alert('no go');
}
>
Quote:
Quote:
function test(obj)
{
if(obj.href.toString().indexOf("page1.html")!= -1){
doSomething();
return false;
}else{
return true;
}
}
>
Quote:
Quote:
>Have you even considered alerting the value of obj.href before deciding that the
browser doesn't work?
>
Quote:
Quote:
--
>
Quote:
I have a test case which shows that this function above works in IE6
if used apart from the whole page. Within a page, it does not work and
follows the link (when it shouldn't). I did not have a deeper look yet
but will work on that shortly. Perhaps, in a meantime, anyone may have
any suggestions for this approach: how effective it is and,
considering all other facts, what other alternative may exist.
>
The approach is fine. Either the value of obj.href is not what you
expect, or your doSomething() function contains errors.
>
--
Finally!

I found the problem. I have some included JS file with
document.onclick = somefunction which returned true. Hah! But how did
Firefox get away with it?.. I do not know :)

Thanks everyone!



Closed Thread