Forum Moderators: mack
on (release) {
getURL("JavaScript:popup();");
}
IN THE HTML PAGE:
<SCRIPT LANGUAGE="JavaScript">
function popup() {
window.open('item1.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=475,height=625,left=50,top=50');
}
</script>
Now this works for item1.html, but the problem lies if I want another popup of lets say, item2.html. I entered the same code again in the HTML PAGE (that holds the movies) that looked like this:
<SCRIPT LANGUAGE="JavaScript">
function popup() {
window.open('item1.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=475,height=625,left=50,top=50');
}
</script>
<SCRIPT LANGUAGE="JavaScript">
function popup() {
window.open('item2.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=475,height=625,left=50,top=50');
}
</script>
Now I have one for item1.html and item2.html.
Problem is that now all buttons only open item2.html
what am i doing wrong? and what about me having over 100 items? anyways to do this with variables so that one <script></script> code is needed for all of them? or is their a better way to do this?
please help. thank you.
criz lunati
You have the same name for your functions. You need to have something more dynamic. You need to pass a parameter to one function that sets the destination page like:
on (release) {
getURL("JavaScript:popup('item1.html');");
}
Then use it in your function like:
<SCRIPT LANGUAGE="JavaScript">
function popup(destination) {
window.open(destination,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=475,height=625,left=50,top=50');
}
</script>
If you want to use the same popup window the add a name to your window as the second parameter of the window.open method.
I have not tested this code so it may need some tweeking.
Is the variable 'destination'? So that whenever I click on any item, for example 'item1' it will plug item1.html into 'destination' and show the popup enlargement of item1?
In this code you are telling the browser to use javascript instead of finding a new page using the javascript protocal(JavaScript:). Then you are telling it which function to use (popup()). We are going to pass the name of the page you want to open, which is 'item1.html' in this case. You just populate the name of the page you want there for the click.
function popup(destination) {
window.open(destination,'', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=475, height=625, left=50, top=50');
}
Now we are telling the function to expect a parameter with the call. If you were to call popup() without a string inside the parenthasis you would get an error. We need to name it something so I just named it destination, since basically thats what it is.
Next we are going to take your original window.open method. This method takes 3 parameters, just like our popup function takes 1, destination. The first is the name of the html to open in the popup. We put destination here which is a variable and holds the value we passed in the original call, 'item1.html'. A side note is that we used quotes to surround the name because it is of a data typr string. A string is basically words and text compared to an integer or a date.
Next we need a name for the popup. As you can see from the original code that you don't have to pass anything. If you want to have control over it and have other things open in it, then you should put some string(name) in there. The last as you can see just gives you all kinds of properties of the window you are opening.
Glad to see it worked. If you are interested in learning Javascript then you can read our jumpstarts:
[webmasterworld.com...]
Welcome to WebmasterWorld!