PDA

View Full Version : Javascript popup help



NUFC1892
Aug 25th, 2003, 10:59 PM
Hi ive just added a javascript popup to one of my pictures then when i come to add another picture and do another javascript popup it opens up the same picture in another window for the same pic when it is suppose to be a different pic for that pop up below is the code:

<script>

//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
//JavaScript

tutorials and over 400+ free scripts

function openpopup(){
var

popurl="Me_In_Home_Shirt.html"
w

inpops=window.open(popurl,"","width=400,height=338,resizable,")
}_</script><a
href="javascript:openpopup()"><img
src="images/Me_In_Home_Shirt.jpg"
alt="" width="352" height="288">
</a> <script>

//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
/

/JavaScript tutorials and over 400+ free scripts

function openpopup(){
var

popurl="Me_In_Away_Shirt.html"
w

inpops=window.open(popurl,"","width=400,height=338,resizable,")
}_</script><a
href="javascript:openpopup()"><img
src="images/Me_In_Away_Shirt.JPG" alt="" width="352"
height="288">

A1ien51
Aug 25th, 2003, 11:06 PM
You can not have the same script more then once on the same page.

You need to do it a different way

please make sure the smile checkbox is checked before posting code!



<script>
function MakePopUp(PopUpUrl){
WinPop=window.open(PopUpUrl,"WinPop","width=200,height=200")
}
</script>

<a href="javascript:MakePopUp('thePageUrl.htm')">HMMM</a>

Cymru
Aug 25th, 2003, 11:07 PM
Hi NUFC1892,

Try this script.

<script>
function openpopup(path,w,h){
win=window.open(path,"","width="+w+",height="+h+",resizable");
}
</script>

<a href="javascript: openpopup('image.jpg',400,300)">
<img src="image.jpg" border="0" alt=""></a>

image.jpg is the name of the image, 400 is the width and 300 is the height.

No need to do it twice though!

NUFC1892
Aug 25th, 2003, 11:27 PM
what ive got is 2 seperate pictures on the site and what i want is when you click on 1 picture it opens it up in a seperate popup window then when you click on the other picture it opens that picture up in another pop up window, but when i add the code i posted it just opens up the same pic for each of the 2 different pics i have, ive looked at the codes you have giving me and im totally confused..

i understand you cant have the same code for 2 seperate pics so is there a way of getting round this so it will open up the correct picture instead of the same one.

Cymru
Aug 25th, 2003, 11:31 PM
Whose script are you using, mine or A1ien51?

With mine you can give each link a different picture. The caych is you have to enter their height and width values as well.

NUFC1892
Aug 25th, 2003, 11:38 PM
I tried yours Cymru but somehow it wouldnt open it in the op up window, would it be possible to post the full script for the 2 seperate pictures i have, like so when u click on a pic it will open in a diff window........

Cymru
Aug 25th, 2003, 11:43 PM
Oops my script had typos.

Try this one instead.

<script>
function openpopup(path,w,h){
win=window.open(path,"","width="+w+",height="+h+",resizable");
}
</script>

<a href="javascript: openpopup('image.jpg',400,300)">
<img src="image.jpg" border="0" alt=""></a>

NUFC1892
Aug 26th, 2003, 12:17 AM
THANKYOU Cymru that worked perfectly and now I can have more than 1 images that use a popup THANKS alot :) :) :) :thumbsup:

NUFC1892
Aug 26th, 2003, 12:20 AM
on more thing do you know how to change the popup windows heading of it because it just shows the path for it instead of an actual heading, as i would like a heading for this popup.

NUFC1892
Aug 26th, 2003, 12:27 AM
sorry but this is also the last thing i swear LOL how do you get the pop up to be centred.

Cymru
Aug 26th, 2003, 12:33 AM
No, you cannot give each picture a title, unless you put each picture into a seperate HTML page.

You can use html files as well in the A tag, and they will open in the popup

<a href="javascript: openpopup('pic1.htm',400,300)"><img src="..."></a>

Cymru
Aug 26th, 2003, 12:36 AM
Ceentered? OK, that will require some major changes to the script.


<script>
function openpopup(url,width,height){
var left=(screen.width/2)-(width/2);
var top=(screen.height/2)-(height/2);
if(window.opera)
top=top-height/2;
window.open(url,'details','height='+height+',width='+width+',left='+left+',top='+top);
}
</script>

<a href="javascript: openpopup('page1.htm',400,300)">
<img src="..." border="0" alt=""></a>

Code your A tags in the same way.

NUFC1892
Aug 26th, 2003, 12:49 AM
Cymru when i puit all together it doest seem to centre it plus i also used this

<a href="javascript: openpopup('pic1.htm',400,300)"><img src="..."></a>

for it to be in a seperate HTML page in which this was good but when i tried sorting the code for it to be centred it just didnt work at all.

Cymru
Aug 26th, 2003, 12:56 AM
Yes, when I posted my script it got screwed up a little.

Copy the corrected script above, it should be correct now.

NUFC1892
Aug 26th, 2003, 01:17 AM
I've managed to do all the other stuff with the seperate HTML stuff heres the code

<script>

function openpopup(path,w,h){

win=window.open(path,"","width="+w+",height="+h+",resizable");

}

</script>
<a href="javascript : openpopup('Me_In_Home_Shirt.html',387,342)"><img
src="Me_In_Home_Shirt.jpg"border="0" alt="" width="191"
height="152"></a>
<script>

function openpopup(path,w,h){

win=window.open(path,"","width="+w+",height="+h+",resizable");

}

</script>
<a href="javascript : openpopup('Me_In_Away_Shirt.html',387,342)"><img src="Me_In_Away_Shirt.jpg"border="0" alt="" width="191"
height="152">
<script>
</a>

What would i do to add that Center thing.

Cymru
Aug 26th, 2003, 01:20 AM
Remove the old script and replace it with this.

<script>
function openpopup(url,width,height){
var left=(screen.width/2)-(width/2);
var top=(screen.height/2)-(height/2);
if(window.opera)
top=top-height/2;
window.open(url,'details','height='+height+',width='+width+',left='+left+',top='+top);
}
</script>

<a href="javascript: openpopup('page1.htm',400,300)">
<img src="..." border="0" alt=""></a>

Cymru
Aug 26th, 2003, 01:24 AM
Also, you must remove the space between java and script

NUFC1892
Aug 26th, 2003, 01:38 AM
I'm confused heres my actual code to make everything work would you be able to do the complete code with the help of mine to do the centre thing for the 2 images i have.

<script>

function openpopup(path,w,h){

win=window.open(path,"","width="+w+",height="+h+",resizable");

}

</script>
<a href="javascript : openpopup('Me_In_Home_Shirt.html',387,342)"><img
src="Me_In_Home_Shirt.jpg"border="0" alt="" width="191"
height="152"></a>
<script>

function openpopup(path,w,h){

win=window.open(path,"","width="+w+",height="+h+",resizable");

}

</script>
<a href="javascript : openpopup('Me_In_Away_Shirt.html',387,342)"><img src="Me_In_Away_Shirt.jpg"border="0" alt="" width="191"
height="152">
<script>
</a>

I would appreciate it if you could put it together for me so it will work on my PC

Cymru
Aug 26th, 2003, 01:45 AM
Well OK, I've got time to spare.

Give me your page and I'll make the changes.

NUFC1892
Aug 26th, 2003, 01:46 AM
Well I aint uploaded it yet on the internet im working from hom on it, but the code is there if you could add the centre thing to it i would appreciate that becuase ive tried adding it but it just dont work.

Cymru
Aug 26th, 2003, 02:02 AM
<script>

function openpopup(url,width,height){
var left=(screen.width/2)-(width/2);
var top=(screen.height/2)-(height/2);
if(window.opera)
top=top-height/2;
window.open(url,'details','height='+height+',width='+width+',left='+left+',top='+top);
}

</script>

<a href="javascript: openpopup('Me_In_Home_Shirt.html',387,342)"><img
src="Me_In_Home_Shirt.jpg" border="0" alt="" width="191"
height="152"></a>

<a href="javascript: openpopup('Me_In_Away_Shirt.html',387,342)"><img
src="Me_In_Away_Shirt.jpg" border="0" alt="" width="191"
height="152"></a>

That's all. There is no need to repeat the script more than once. If you want to add another picture just write:

<a href="javascript: openpopup('Other_Shirts.html',387,342)"><img src="Other_Shirts.jpg" border="0" alt="" width="191" height="152"></a>

Remove the spaces between java and script of course.

NUFC1892
Aug 26th, 2003, 02:09 AM
that code didtn work that you posted with the added centre thing on, it came up with a runtime error then when i clicked on an image for it to be poped up in went to a new page......

Cymru
Aug 26th, 2003, 02:14 AM
The forum keeps messing about with whatever I write.

Download the file below and copy it into your page. If you're still getting problems then it must be how you implement it, because they work fine on my PC.

NUFC1892
Aug 26th, 2003, 02:22 AM
THANKYOU Cymru it works now im real real happy, ive been trying to get this to work all day and decided to come to a forum and you have helped me a great deal, CHEERS

:) :thumbsup: :)

Cymru
Aug 26th, 2003, 02:25 AM
That's OK, glad I could help. :)

Christ! That was painful