Click to See Complete Forum and Search --> : javascript popup from image


ezryder
04-11-2004, 05:07 PM
Hi,
I have been using the attached script along with a flash file to open a new window. I want to adapt the script to open the flash file from an image, i.e. when the user clicks on the image the popup window opens with my flash file.

Can anyone tell me what to put in this code in order to do this please?


<SCRIPT LANGUAGE='JavaScript'>

function popUp(){
window.open('../Games/Link.swf','','scrollbars=no,height=550,width=720,left=0,top=0');
}

</script>


Thanks in advance

steelersfan88
04-11-2004, 05:09 PM
keep that in the head section, and make the image appear like:<img src="..." alt="..." onclick="popUp()">

ezryder
04-12-2004, 04:20 AM
Thanks for the reply.

I have tried this but it doesn't seem to work, now I have the following script in the header:


<SCRIPT LANGUAGE='JavaScript'>

function popUp(){
window.open('../Games/Angles.swf','','scrollbars=no,height=550,width=720,left=0
,top=0');
}

</script>


and this in the body:


<img src="Flash%20buttons/Movie3.gif" alt = "Alternate text" width="200" height="135"onclick="popUp()">



I know next to nothing about javascript and html but I looked up what the alt parameter was and I read this is alternative text in case the image doesn't display.

I'm also wondering if I want to display two images on the page given that the link is defined in the javascript section how would I do this.

Apologies for the simple questions - is there a tutorial which covers this? I've looked but I can't find any.

Thanks again.

steelersfan88
04-12-2004, 07:38 AM
This should work:<script type="text/javascript">

function popUp() {
// left and top are supposedly IE only
var newWin = window.open('../Games/Angles.swf','_blank','height=550,width=720,left=0,top=0');
// this will create an error if game not on same server as opener
newWin.moveTo(0,0)
}

</script>

<img src="Flash%20buttons/Movie3.gif" alt="Alternate text" width="200" height="135" onclick="popUp()">
<!-- Content -->
<img src="Flash%20buttons/anotherPicture.gif" alt="Alternate text" width="200" height="135" onclick="popUp()">That has two pictures, there are many javascript tutorials, use the search feature on these forum. Here are 2 fro ma good friend:[list=1]
http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=0&TOshow=allshow
http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/ix.html
[/list=1]

ezryder
04-12-2004, 11:00 AM
Thanks again that worked for me.

However, I didn't quite phrase what I said correctly, what I meant was how would I have two different links on the same page from two different pictures given that the link is specified in the javscript already?

ezryder
04-12-2004, 11:08 AM
OK I think I figured it out ... just call the javascript function popup2 and refer to that in the link. Is this the best way?

steelersfan88
04-12-2004, 11:09 AM
If I understand you correctly, you would have to send the URL as an argument to the url parameter, as such:<script type="text/javascript">

function popUp(url) {
// left and top are supposedly IE only
var newWin = window.open(url,'_blank','height=550,width=720,left=0,top=0')
;
// this will create an error if game not on same server as opener
newWin.moveTo(0,0)
}

</script>

<img src="Flash%20buttons/Movie3.gif" alt="Alternate text" width="200" height="135" onclick="popUp('../Games/Angles.swf')">
<!-- Content -->
<img src="Flash%20buttons/anotherPicture.gif" alt="Alternate text" width="200" height="135" onclick="popUp('../Games/NewGame.swf')">Send the source of the game in ('Source') :)