Click to See Complete Forum and Search --> : Jacascript Help
Napster
04-12-2004, 01:40 AM
I want to make part of my php program to have it so that if I put my mouse over a link a new window will popup showing a certain file and then once I move my mouse off of the link it will close the window? How would I do this? I know how to do some Javascript but very little and I know how to echo JS in a PHP code. But how would I do this certain code. Any code will be helpful thanx
bad76
04-12-2004, 03:01 AM
Hi,
I think this is the best guide you can find on javascript (http://www-eleves-isia.cma.fr/documentation/Web/javascript/javascri/contents.htm) on the net. Because all this is surely 100% supported by any browser. For a more complete guide I suggest www.w3cschools.com.
But, now, your problem.
You have to set two event for the link, onmouseover and onmouseout.
<a href="#" onmouseover="some Js instruction" onmouseout="other Js instruction" >
Now, for open and close a window JS has two function:
window.open and window.close
<script>var mywin</script>
<a href="#" onmouseover="mywin=window.open('myurl','targetname','some option')" onmouseout="mywin.close()" >
You now have two problem:
- first, the popup killer. May be window.open can file because the user has a popup killer. You can't do anything to avoid this.
-second: window.close can ask to user EACH TIME if he want really close the window.
To avoid this second problem you can let the window open, but put it on back. To do this use focus() function:
<script>var mywin</script>
<a href="#" onmouseover="mywin=window.open('myurl','targetname','some option'); mywin.focus()" onmouseout="this.focus()" >
May be this last code is the best solution. Ah! Search in the guide for the cool option in window.open function...
Bye bye
Napster
04-12-2004, 03:25 AM
Well right now my code is
<script>
function openpopup(){
var popurl="tree.jpg"
winpops=window.open(popurl,"","width=20,height=20,status,")
}
</script>
<a target="img" onMouseOver="javascript:openpopup()" onMouseOut="self.close(img);">Mouse here to open the file</a>
but I can not seem to get it to close
bad76
04-12-2004, 01:51 PM
Your are wrong.
self.close() send a document close() to main window. Nothing to do with winpops.close()...
Look:
<script>
var winpops
function openpopup(){
var popurl="tree.jpg"
winpops=window.open(popurl,"img","width=20,height=20,status,")
}
</script>
<a href="#"
onmouseclick="return false;"
onMouseOver="openpopup()"
onMouseOut="winpops.close()">Mouse here to open the file</a>
First: if you want a target, you have to write into window.open, the second argument you pass.
Second: declare a variable as global container for reference the window
Third: you have to write an href="something" or the anchor is not created. To stop the mouse click on the anchor just insert onmouseclick="return false;".
I hope this helps you...
ps: ehm... disable the smilies...
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.