Forum Moderators: open

Message Too Old, No Replies

TARGET and ONCLICK not working together in link

link works with target or onclick, but not both

         

developing web

5:51 pm on Jul 21, 2003 (gmt 0)

10+ Year Member



I am having trouble getting the following test page to work correctly on a computer with ie6:

<html>
<body>
<a href="test2.html" target="_blank" onclick="alert('Blah')">
Click
</a>
</body>
</html>

When the user clicks the link, he gets the "Blah" alert window. However, when he clicks the OK button, he gets a beep and nothing more.
Both <a href="test2.html" target="_blank"> and <a href="test2.html" onclick="alert('Blah')"> work as one would expect. However, combining the two options will not.
Any ideas?

hutcheson

6:49 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's the return value.

The function "alert()" should return 1 (to say 'I took care of it, don't take the HREF link') or 0 (to say 'now do the HREF link, please').

Obviously alert() returns what it returns; so you may need to wrap it in your own function:

function myalert() {
alert("blah");
return 0;
}

This is from memory; I may have the values reversed.

DrDoc

8:26 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!

You can also do it inline like this:

<a href="test2.html" target="_blank" onclick="alert('Blah');return true;">
Click
</a>

developing web

12:23 pm on Jul 22, 2003 (gmt 0)

10+ Year Member



Thanks for the suggestions. Unfortunately, neither of these works. The puzzling part is that

<a href="hans2.html" onclick="alert('Blah');return true;">

presents the alert message, then displays hans2.html in the current browser. It is only when the TARGET attribute is added that it fails to work.
However,

<a href="hans2.html" target="_blank">

displays hans2.html in a new browser, but fails when the ONCLICK is added. So it seems that each part of this works correctly until they are used together.

DrDoc

8:56 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then let's try it without onclick:

<a href="test2.html" target="_blank" onmousedown="alert('Blah');">
Click
</a>

developing web

6:02 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



Dr,
I tried:

<a href="hans2.html" target="_blank" onmousedown="alert('Blah');">
Click
</a>

This not only doesn't work on the computer in question, but it also fails to do anything after the alert on computers which worked fine using onclick. They now display the alert, then nothing. Suspecting that onmousedown was preventing the click action from occuring, I tried also onmouseup, which produced the same lack of action.

DrDoc

12:21 am on Jul 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just tried this on my computer (also running IE6):

<a href="http://wap.google.com" target="_blank" onclick="alert('Blah');return true;">
Click
</a>

...and it worked just fine.

<a href="http://wap.google.com" target="_blank" onblur="alert('Blah');return true;">
Click
</a>

Also worked, but then the alert pops up behind the new window.

TGreene

4:55 pm on Jul 28, 2003 (gmt 0)

10+ Year Member



I too am trying to do something similar, but to no avail...

I am using the onMouseOver and onClick commands in conjunction with CSS, to convert a table into icons, but am having a helluva time getting the links to open in a seperate frame.


<TR>
<TD BGCOLOR="#DEDFDF" VALIGN=MIDDLE ALIGN=LEFT WIDTH=110 onMouseover="this.style.backgroundColor='#C6C5D3'; this.style.cursor='hand';" onMouseout="this.style.backgroundColor='#DEDFDF'" onclick="window.location.href='ranges.htm' TARGET='main'"> <FONT SIZE=-2 COLOR="#7667A6"><DD>Ranges</TD>
</TR>

Here's a link to our corporate website, so you can see what I'm attempting to do... [castlestove.com...]

developing web

5:12 pm on Jul 28, 2003 (gmt 0)

10+ Year Member



TGreene,
Try:

onclick="parent.main.location='ranges.htm'"

instead of:

onclick="window.location.href='ranges.htm' TARGET='main'"

Richard

TGreene

5:30 pm on Jul 28, 2003 (gmt 0)

10+ Year Member



SWEET -- It worked beautifully!

developing web

7:01 pm on Jul 28, 2003 (gmt 0)

10+ Year Member



As for the original question, I tried the code as originally posted on a couple other WinXP, ie6 PCs and it worked fine. So, I have concluded that the problem lies in this particular PC. Next step - side-by-side comparison to identify the differences.