473,406 Members | 2,710 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,406 software developers and data experts.

onclick="alert('hello');return false;" does not work in IE7?

Hi,

Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');return
false;">link</a>

will stop the browser from actually going to href's destination.
However, this is not the case with the IE7 I am using. What has
changed?

IE7 version: 7.0.5730.11. Update versions: 0

Has anyone bumped into this problem before? How do I get around it?
Thanks.
Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');return
false;">my test link</a>
</body>
</html>

Dec 5 '06 #1
13 38500
al******@gmail.com wrote:
Hi,

Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');return
false;">link</a>

will stop the browser from actually going to href's destination.
However, this is not the case with the IE7 I am using. What has
changed?
You have a newline after 'return', so javascript will insert a semicolon
before 'false'. Try taking out the newline and it works fine.

Dec 5 '06 #2

al******@gmail.com wrote:
Hi,

Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');return
false;">link</a>

will stop the browser from actually going to href's destination.
However, this is not the case with the IE7 I am using. What has
changed?
[...]
Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');return
false;">my test link</a>
</body>
</html>
The HTML is invalid, an A element must be inside a block element. I'm
amost certain that has nothing to do with it, particularly where IE is
concerned, but you never know! ;-)

--
Rob

Dec 5 '06 #3
RobG wrote:
al******@gmail.com wrote:
>Hi,

Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');return
false;">link</a>

will stop the browser from actually going to href's destination.
However, this is not the case with the IE7 I am using. What has
changed?
[...]
>Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');return
false;">my test link</a>
</body>
</html>

The HTML is invalid, an A element must be inside a block element. I'm
amost certain that has nothing to do with it, particularly where IE is
concerned, but you never know! ;-)
That only goes for XHTML. And since there's no doctype, IE will imply
HTML4, iirc. I'm with Duncan Booth elsewhere in this thread: the newline
is the problem.

--
Martijn Saly
Dec 5 '06 #4

Hi,

The newline is just a formatting problem with google. It does not
exist in the actual code.

In addition, I tried putting the linking inside <p></p>, but the
problem is still there.... other suggestions?

Thanks.
Martijn Saly wrote:
RobG wrote:
al******@gmail.com wrote:
Hi,

Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');return
false;">link</a>

will stop the browser from actually going to href's destination.
However, this is not the case with the IE7 I am using. What has
changed?
[...]
Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');return
false;">my test link</a>
</body>
</html>
The HTML is invalid, an A element must be inside a block element. I'm
amost certain that has nothing to do with it, particularly where IE is
concerned, but you never know! ;-)

That only goes for XHTML. And since there's no doctype, IE will imply
HTML4, iirc. I'm with Duncan Booth elsewhere in this thread: the newline
is the problem.

--
Martijn Saly
Dec 5 '06 #5
ASM
al******@gmail.com a écrit :
other suggestions?
Perhaps you have a tag 'object' or 'embed' or 'applet' in same page ?
if yes, it is a problem with your Windows !
I've heard the last update added something blocking popups.

M$ have then published a medicine
(something to break the protection they have just created ... ! ! ! !)

You'ld have to put after last <object ...>

<script type="text/javascript" src="ieupdate.js"></script>

and have this ieupdate.js in same folder.

file 'ieupdate.js' :
====================
objects = document.getElementsByTagName("object");
for (var i = 0; i < objects.length; i++)
{
objects[i].outerHTML = objects[i].outerHTML;
}

<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/activating_activex.asp>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 5 '06 #6
VK

ASM wrote:
Perhaps you have a tag 'object' or 'embed' or 'applet' in same page ?
if yes, it is a problem with your Windows !
I've heard the last update added something blocking popups.

M$ have then published a medicine
(something to break the protection they have just created ... ! ! ! !)

You'ld have to put after last <object ...>

<script type="text/javascript" src="ieupdate.js"></script>

and have this ieupdate.js in same folder.

file 'ieupdate.js' :
====================
objects = document.getElementsByTagName("object");
for (var i = 0; i < objects.length; i++)
{
objects[i].outerHTML = objects[i].outerHTML;
}
That is the old Eolas workaround, nothing to do with links or popups.
Eolas' "no activation w/o interaction" block is not IE or Windows
specific: it is the same for any law-obeyant UA made over the last
year-and-half. btw this old workaround was contested as legally clean
because the object tag source code is still coming from the page.
document.write from external file is the current way (see my "Eolas
workaround" post)

Dec 5 '06 #7
VK
al******@gmail.com wrote:
Hi,

Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');return
false;">link</a>

will stop the browser from actually going to href's destination.
However, this is not the case with the IE7 I am using. What has
changed?
The security, I presume. That must be against the common trick "show
one URL in status bar, go to another one that mimics it". I guess you
may turn it off somewhere but you cannot expect it from your visitors.

If it is what I'm thinking it is, the psi-links of a kind
<a href="noscript.html" onclick="myFunction(); return false;">Select
all</ais another thing to say bye-bye sooner is better (the first one
is "holly hack")

Dec 5 '06 #8
al******@gmail.com wrote :
Hi,

Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');return
false;">link</a>

will stop the browser from actually going to href's destination.
However, this is not the case with the IE7 I am using. What has
changed?

IE7 version: 7.0.5730.11. Update versions: 0

Has anyone bumped into this problem before? How do I get around it?
Thanks.
Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');return
false;">my test link</a>
</body>
</html>
The problem, I think, is that IE7, at least for A tags, first tries to go
to href, and AFTER that, tries to execute onClick actions.
In fact :
<a href="javascript:null()" onClick="alert('clicked');"></a>
Doesn't work in IE, since null() stops JS.
On the other hand, that works:
<a href="#" onClick="alert('clicked');"></a>

I don't know why IE was made this way, since it is absolutely illogical
but I do not try to understand M$ anymore now...

Juste try to replace href="#" and then, test once again, and tell us :)

--
Naixn
http://fma-fr.net
Dec 5 '06 #9

I am not sure what is the problem, but this is the work around I am
using now:

<a href="javascript:;" onclick="foo(); return false;">link</a>

Not the best...
naixn wrote:
al******@gmail.com wrote :
Hi,

Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');return
false;">link</a>

will stop the browser from actually going to href's destination.
However, this is not the case with the IE7 I am using. What has
changed?

IE7 version: 7.0.5730.11. Update versions: 0

Has anyone bumped into this problem before? How do I get around it?
Thanks.
Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');return
false;">my test link</a>
</body>
</html>

The problem, I think, is that IE7, at least for A tags, first tries to go
to href, and AFTER that, tries to execute onClick actions.
In fact :
<a href="javascript:null()" onClick="alert('clicked');"></a>
Doesn't work in IE, since null() stops JS.
On the other hand, that works:
<a href="#" onClick="alert('clicked');"></a>

I don't know why IE was made this way, since it is absolutely illogical
but I do not try to understand M$ anymore now...

Juste try to replace href="#" and then, test once again, and tell us :)

--
Naixn
http://fma-fr.net
Dec 6 '06 #10
al******@gmail.com wrote:
Normally, a piece of code such as

<a href="http://www.yahoo.com" onclick="alert('hello');
return false;">link</a>

will stop the browser from actually going to href's
destination. However, this is not the case with the IE7
I am using. What has changed?

IE7 version: 7.0.5730.11. Update versions: 0
Trying exactly that code (inadvertent line wrapping removed), in exactly
that version of IE 7, reveals no issue. The navigation is cancelled as
expected.
Has anyone bumped into this problem before?
Lots of people fail to properly attribute cause and effect relationships
when scripting web browsers. An inability to post code that demonstrates
the issue if often a symptom of failing to properly attribute its cause
and effect relationships.

Where you say, "code such as" you probably mean code that consists of a
function call followed by a - return false; - statement. It has always
been the case that if an exception is thrown in the function call the
event handling function stops executing prior to the - return false; -
statement and so never returns any value at all to cancel the navigation
or not. Thus the navigation happens.
How do I get around it?
It is possible that some change in IE has started to cause the function
you call to start throwing exceptions and prevent your onclick handlers
ever getting to the - return false; - statement. It is identifying that
change that will facilitate the correct solution to your problem.
Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');
return false;">my test link</a>
</body>
</html>
If you are going to post a test case it is always a good idea to test it
yourself to verify that it does demonstrate what you expect it to
demonstrate. In practice this test case shows the alert and does not
navigate the browser (using IE7 version: 7.0.5730.11. on Windows XP
SP2).

Richard.
Dec 9 '06 #11
"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote:
>Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');
return false;">my test link</a>
</body>
</html>

If you are going to post a test case it is always a good idea to test it
yourself to verify that it does demonstrate what you expect it to
demonstrate. In practice this test case shows the alert and does not
navigate the browser (using IE7 version: 7.0.5730.11. on Windows XP
SP2).
The test case *as the OP posted it* does show what he claimed. It shows the
alert and then navigates to the link (in any browser, not just IE 7).

Maybe the bad line-break wasn't his original problem, but it seems a touch
unfair to chastise him for posting a bad test case when in fact what he
posted did what he said until you corrected the line wrapping.
Dec 9 '06 #12
Duncan Booth wrote:
Richard Cornford wrote:
>>Testcase:
-----------------------
<html>
<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');
return false;">my test link</a>
</body>
</html>

If you are going to post a test case it is always a good
idea to test it yourself to verify that it does demonstrate
what you expect it to demonstrate. In practice this test case
shows the alert and does not navigate the browser (using IE7
version: 7.0.5730.11. on Windows XP SP2).

The test case *as the OP posted it* does show what he
claimed. It shows the alert and then navigates to the
link (in any browser, not just IE 7).
So it does not show any change between IE 6 and 7, and as the OP's
question took the form "What ahs changed?" (in part) its obviously
faulty formatting can be dismissed as ineptitude on the part of the
individual doing the posting.
Maybe the bad line-break wasn't his original problem, but it
seems a touch unfair to chastise him for posting a bad test
case when in fact what he posted did what he said until you
corrected the line wrapping.
But if he had tested what he had before he posted it he would not have
found that it did not exhibit the behaviour attributed to it, and
instead of having our time wasted with miss-attributed cause we could
have been looking at something that really has changed between IE 6 and
7 and maybe learnt something of ongoing practical use (though more
likely seen that an exploitable bug in IE 6 had finally been fixed).

Richard.
Dec 10 '06 #13
RobG wrote:
al******@gmail.com wrote:
[...]
>Testcase:
-----------------------

<html>

<body>
<phello1 </p>
<a href = 'http://www.yahoo.com' onclick="alert('clicked');return
false;">my test link</a>
</body>
</html>

The HTML is invalid, an A element must be inside a block element.
IBTD.
I'm amost certain that has nothing to do with it, particularly where IE
is concerned, but you never know! ;-)
When there is no DOCTYPE declaration in the markup, or one that can be
deduced from additional facts in the posting (like VK stating Validator
results), it makes little sense to point out possible invalid snippets,
provided that there is an active (X)HTML standard that can be referred to
where it can still be Valid.

For example, if the above HTML code was declared HTML 4.01 Transitional (as
it would be considered by a recent UA implementing a Quirks Mode), would
still be not pretty, but perfectly Valid.
Regards,

PointedEars
--
The German psychs, the German authorities, the German secret service agents
are [...] fanatics, they are insane and known of persecuting innocent people
and Scientologists. -- "The only real Barbara Schwarz", dsw.scientology,
<16**************************@posting.google.com >
Dec 11 '06 #14

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

Similar topics

4
by: Armel Asselin | last post by:
Hello, I'm working on a Javascript interpreter; when I execute this code I cannot figure out why the inner "c" function returns the input widget as "this"... could someone tell ?? <input...
1
by: knocte | last post by:
Hello group. In the following testcase I attach to the final of the message, I have two questions: 1) According to comment # 1, how can I pass an argument to the function that way? 2)...
3
by: frank.cleuren | last post by:
Hello, The following code: function checkChildMenuItems(strNameModule) { alert(document.getElementById(strNameModule).checked); } <input name="strMenuQA" id="strMenuQA" type="checkbox"...
2
by: Peter | last post by:
Hi, this is the code, and new row and new cell generated ok, but why the onclick and onmouseover doen't work? Thank you in advance! <html> <head> <script language="javascript"> function...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
1
by: Anup | last post by:
In my form I and doing validations using 'Javascript' as I m using ASP1.1 and there is very less support for Validators there. //Code Behind private void Page_Load(object sender,...
5
by: Jason | last post by:
Hello, I am trying to dynamically create a table, then set its <td>'s onclick: var table = document.createElement("table"); var row = table.insertRow(-1); var td = row.insertCell(-1);...
1
by: Big George | last post by:
Hello, Controls on webpage: - Datagrid - TextBox Datagrid has Delete button: <asp:TemplateColumn HeaderText="Borrar"> <HeaderStyle Width="10%"></HeaderStyle>
7
by: SM | last post by:
Hello, i need to add a classname to an element <ausing JavaScript. I've tried a couple of thing with no success. This is an small piece of my code: .... <li><a href="<?php echo $cd_img; ?>"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.