View Full Version : script conflict
charrington
11-18-2002, 05:43 PM
i have a page that needs several popup windows (activated by a text link).
i am using this script...
<script>
//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
//JavaScript tutorials and over 400+ free scripts
function openpopup(){
var popurl="futurepetid.html"
winpops=window.open(popurl,"","width=400,height=250,scrollbars,left,")
}
</script>
<a href="javascript:openpopup()">Pet Location
Device</a>
it works fine until i go to insert it again using a different url, and new text link.
the second instance of the script calls up the first url. this seems to happen only after i upload ...seems to be OK working locally.
beetle
11-18-2002, 06:44 PM
You need to pass parameters to the function for this to work...<script>
function openpopup(popurl){
winpops=window.open(popurl,"","width=400,height=250,scrollbars,left,")
}
</script>
<a href="futurepetid.html" onclick="openpopup(this.href); return false;">Pet Location
Device</a>
<a href="someotherpage.html" onclick="openpopup(this.href); return false;">Something Else</a> Now that you see how this works, please allow me to:
<rant>
I REALLY wish javascriptkit.com would remove this pointless, unhelpful script. If I had a dollar for every CF newcomer that posted about this script I'd be like Warbucks' spoiled grandchild. If anyone listening has the power to do so, PLEASE, remove this thing! This script does NO BENEFIT to anyone and instead: (1) causes problems like charrington's (2) teaches bad programming practice (3) teaches bad web usability.
</rant>
charrington
11-19-2002, 03:32 PM
your new code works...thanks for your help.
can you recommed a good starter book for me? i don't like to just cut and paste stuff, particularly when i run into problems, but i am a total newbie to javascript.
thanks
beetle
11-19-2002, 04:36 PM
Sorry, I'm afraid not. I never learned any Javascript from a book, and I learned all my basic programming know-how in High-school and college. If book-learning is your thing, ask around here, I'm sure someone knows of some good titles.
THANK YOU Beetle and charrington!!!
This was driving me crazy! I needed to open two separate html files from two separate links on the same page. The code wasn't letting me. Grrr...
Now, using Beetle's code, I can indeed open separate html's from separate links.
I've been self teaching myself JavaScripts and have found this site, and forum, VERY USEFUL.
Another question if I may:
Now that I have separate html files opening from the separate links----how can I specify different popup window sizes for each individual link?
For instance, the first link pops up a window of size “width=720, height=420”.
The second pop up window (on the same page), I’d prefer something like “width=630, height=420”.
One script seems to overrule the other...
Cheers!
Wes
glenngv
11-26-2002, 04:10 AM
use another parameters:
<script>
function openpopup(popurl,target,w,h){
winpops=window.open(popurl,target,"width="+w+",height="+h)
}
</script>
<a href="futurepetid.html" target="future" onclick="openpopup(this.href,this.target,630,420); return false;">Pet Location
Device</a>
<a href="someotherpage.html" target="other" onclick="openpopup(this.href,this.target,500,300); return false;">Something Else</a>
beetle
11-26-2002, 04:11 AM
What we are really addressing here is the concept of passing data to a function as parameters (also called arguments) and then receiving those parameters as variables for use in the function. In my first example, we pass the href of the link to the function which is received by the parameter variable, popurl. So, what do we need for the width and height? Just two more parameters!! (and basic knowledge of string concatenation :D) Let's add one for the target too.function openpopup(popurl, targ, w, h) {
var features = "width="+w;
features += ", height="+h;
features += ", scrollbars";
winpops=window.open(popurl,targ,features)
}
</script>
<a href="futurepetid.html" target="myWin" onclick="openpopup(this.href,this.target,720,420); return false;">Pet Location
Device</a>
<a href="someotherpage.html" target="myWin" onclick="openpopup(this.href,this.target,630,420); return false;">Something Else</a>
Thanks again glenngv and beetle!!!
Thanks for a speedy response too. It works!
I've had a couple quarters of C programming at college and understand some about functions and passing parameters etc. My programming abilities are still pre-natal at best.
The page is working GREAT now. Nothing like being able to bend computers to OUR wills.
I've gone a step further and added...
features += ", left=150";
features += ", top=90";
features += ",resizable";
...to enable user resizing of the pop up and for orientation on the screen.
This stuff can be addicting! You guys rock.
Regards,
Wes
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.