PDA

View Full Version : onmouseover AND onClick help please


Cybertooth Tiger
02-15-2003, 10:05 PM
I have a script for the mousover working fine, however, I want to add an "onClick" to open a new window.

This is the script in the head...

<SCRIPT language="javascript">
<!--
function launchwin()
{
window.open("map.html", "width=300,height=300");
}
//-->
</SCRIPT>


And in the table......


<td>
<a href="map.html" onClick="launchwin();"
onmouseover="changeImages('coverage', 'images/coverage-06.gif'); return true;"
onmouseout="changeImages('coverage', 'images/coverage.gif'); return true;">
<img name="coverage" src="images/coverage.gif" width="140" height="38" border="0" alt=""></a></td>

But this only seems to link through to another page (ie: "self"), no pop up?

I could use target="blank" however the map is quiet small, and the project requires this layout (long story).

I want the URL of the new window to be map.html, so not sure if I need both the URL's in there.

Can someone please let me know where I am going wrong.

Many Thanks in advance.

Tonz

redhead
02-15-2003, 10:14 PM
try <a href="javascript:launchwin()"> in your link instead of href="map.html" and the onclick... or put href="#" onclick="launchwin(); return false;"

does that help? :thumbsup:

Cybertooth Tiger
02-15-2003, 10:47 PM
Thanks redhead. But I am now getting an error message?!?!

Is this correct?


<td>
<a href="javascript:launchwin();"
onmouseover="changeImages('coverage', 'images/coverage-06.gif'); return true;"
onmouseout="changeImages('coverage', 'images/coverage.gif'); return true;">
<img name="coverage" src="images/coverage.gif" width="140" height="38" border="0" alt=""></a></td>


Tankx

Tonz:confused:

cheesebagpipe
02-15-2003, 11:06 PM
The second argument to window.open() is the name of the new window - window 'features' comes third:

function launchwin(url)
{
window.open(url,"mapwin","width=300,height=300");
return false;
}
.........

<a href="map.html" target="mapwin" onclick="return launchwin(this.href)"
onmouseover="changeImages('coverage', 'images........

brothercake
02-16-2003, 04:40 AM
cheesebagpipe's example is right - you should *never* use the javascript: pseudo protocol except inside javascript-written links, because in non-javascript browsers they don't do anything - using an href and controlling the onclick return is the best way.

redhead
02-16-2003, 04:24 PM
"you should *never* use the javascript: pseudo protocol"

brothercake... hmm? thats why i said: or put href="#" onclick="launchwin(); return false;" ;)... ah well... im not an expert at javascript, is launchwin(); return false; wrong?

brothercake
02-16-2003, 07:05 PM
Originally posted by redhead
hmm? thats why i said: or put href="#" onclick="launchwin(); return false;"

Yeah cool - I was just re-inforcing the point; that href and onclick/return false is the right way of doing it (assuming that # is a real link, not just #)

Cybertooth Tiger
02-16-2003, 08:02 PM
Awesome help - many thanks - I will go try this soon.

Many, many, many thanks.

Tonz