| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Registered User
Join Date: Jul 2004
Posts: 15
|
Javascript pop up help
Sorry if this is a real dumb question, i have done some searching on the net and cant seem to find a solution for this script i have a bunch of pages that are all pop ups and i just want to place a link in them changes the main (parent) window. the popup script is: <script type="text/javascript"> //<![CDATA[ function popup(url,windowname,width,height) { width=(width)?width:screen.width/3; height=(height)?height:screen.height/3; var screenX = (screen.width/2 - width/2); var screenY = (screen.height/2 - height/2); var features= "width=" + width + ",height=" + height; features += ",screenX=" + screenX + ",left=" + screenX; features += ",screenY=" + screenY +",top=" + screenY; var mywin=window.open(url, windowname, features); if (mywin) mywin.focus(); return mywin; } //]]> </script> any javascript gurus know what it is i need to add or put in my link to sort this?? cheers d |
|
|
|
|
|
#2 (permalink) |
|
trouble free and loverlee
Join Date: Mar 2003
Location: YooKay
Posts: 2,874
|
You can target the main/opener window from the popup window via the use of opener. window.opener.location = … More info: http://www.webreference.com/js/tutorial1/opener.html |
|
|
|
#4 (permalink) |
|
Registered User
Join Date: Jul 2004
Posts: 15
|
actually it seems to work in IE mac (and im assuming on PC) but this doesnt work on safari on mac, any ideas why that is? altered code is: <script type="text/javascript"> //<![CDATA[ function popup(url,windowname,width,height) { width=(width)?width:screen.width/3; height=(height)?height:screen.height/3; var screenX = (screen.width/2 - width/2); var screenY = (screen.height/2 - height/2); var features= "width=" + width + ",height=" + height; features += ",screenX=" + screenX + ",left=" + screenX; features += ",screenY=" + screenY +",top=" + screenY; window.name = "main"; var mywin=window.open(url, windowname, features); if (mywin) mywin.focus(); return mywin; } //]]> </script> and in the pop up <a href="http://www.mylink.com" target="main" onclick="self.close();">Link</a> |
|
|
|
#5 (permalink) |
|
trouble free and loverlee
Join Date: Mar 2003
Location: YooKay
Posts: 2,874
|
Which bit isn't working? The opener method will work in any browser, but you don't seem to be using it. How you create the popup is actually not that important when it comes to targeting the main window from the popup. Your current method of targeting the main window from the popup simply revolves around referring to the main window as 'main'. I'm guessing that you're main window uses frames and 'main' is actually the name of a frame within that frameset? Is that correct? It's no longer clear to me what you are trying to achieve and how you currently have things set out. Do you have an online example where I/we can see what's going on first hand? |
|
|
|
#6 (permalink) |
|
Registered User
Join Date: Jul 2004
Posts: 15
|
Ahh ok, i think i understand it a bit more now, ive realised im not using the opener atall. ive looked again at the link u refrenced but im still unclear on how i would put the opener tag into the javascript (soz i think i am being really thick here!) what i thought i was supposed to do is put the window.name = "main"; into the script that opens the window (and thats how i thought i was naming the parent window) and then all i needed to do was refrence it as target="main" in the link in the popup! I think i may have my wires a little crossed and now i dont really understand what i should be doing. Ill PM you a link to what im trying to do as id rather not have the site listed on this forum. hope you can shed some light on me being a javascript idiot! d |
|
![]() |