473,394 Members | 1,750 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,394 software developers and data experts.

IE6 Ignores JavaScript's return false on a Link

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;
}
}

Apr 17 '07 #1
8 6486
vu******@gmail.com said the following on 4/17/2007 12:29 PM:
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).
<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/
Apr 17 '07 #2
On Apr 17, 12:41 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
vunet...@gmail.com said the following on 4/17/2007 12:29 PM:
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).
<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/
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;
}
}

Apr 17 '07 #3
vu******@gmail.com said the following on 4/17/2007 3:18 PM:
On Apr 17, 12:41 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>vunet...@gmail.com said the following on 4/17/2007 12:29 PM:
>>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).
>><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>
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/
Apr 17 '07 #4
On Apr 17, 6:00 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
vunet...@gmail.com said the following on 4/17/2007 3:18 PM:
On Apr 17, 12:41 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
vunet...@gmail.com said the following on 4/17/2007 12:29 PM:
>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).
><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>
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.

Apr 17 '07 #5
Lee
vu******@gmail.com said:

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

Apr 17 '07 #6
On Apr 17, 6:13 pm, Lee <REM0VElbspamt...@cox.netwrote:
vunet...@gmail.com said:
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?

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

Apr 18 '07 #7
Lee
vu******@gmail.com said:
>
On Apr 17, 6:13 pm, Lee <REM0VElbspamt...@cox.netwrote:
>vunet...@gmail.com said:
>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?

--

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

Apr 18 '07 #8
On Apr 18, 9:48 am, Lee <REM0VElbspamt...@cox.netwrote:
vunet...@gmail.com said:


On Apr 17, 6:13 pm, Lee <REM0VElbspamt...@cox.netwrote:
vunet...@gmail.com said:
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?
--
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!

Apr 19 '07 #9

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

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
15
by: Davide R. | last post by:
Ciao a tutti, vi spiego il mio problema Ho una pagina HTML che referenzia un CSS esterno. Ho alcuni elementi HTML che appartengolo ad una classe (chiamiamola "class1"). Avrei la necessitą,...
7
by: Marci | last post by:
I found this script for cascading menus, however, I cannot reach the author to solve the bug I am having when I add a second menu to it. My problem is this: If I click on the first link, the...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
3
by: jimmygoogle | last post by:
I posted earlier with a scope problem. I think I resolved it in IE but in Firefox it still exists. Anyone have any ideas/experience with this? I attached my code sorry it is so long. You can...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
4
by: bboyle18 | last post by:
Hi, I am working with a table sorting script which can be found here http://www.workingwith.me.uk/articles/scripting/standardista_table_sorting This script works very nicely, but when there is a...
1
by: bsprogs | last post by:
I am currnetly programming a file hosting website in PHP and I am slowly integrating AJAX into the website. Here is my problem: The user uploads the file. The server processes the file and...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.