|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
using window.opner in jscript problem
Hi, guys,
I got a weired problem when trying to use the window.opener object. I need to open a new window from a home page, and once I get into the new window(it's actually on another site), I need to get the url of the calling window(the window that opened the current window). I can use the window.opener.location.href to set a new url for the old window, for example <script language="JavaScript"> <!-- function getURL() { if (window.opener) { alert("This window was opened by another window."); window.opener.location.href="www.yahoo.com"; window.close(); } else{ alert("This window was not opened by any other windows."); } } //--> </script> which does work. Now the weired thing is that, when I try to get the value of the old window's URL like that: <script language="JavaScript"> <!-- function getURL() { if (window.opener) { alert("This window was opened by another window."); var myOpener = window.opener.location.href; //doing something here with the myOpener // } else{ alert("This window was not opened by any other windows."); } } //--> </script> The program just won't work. Somebody got a feel on that? thanks in advance! Tony |
|
#2
|
||||
|
||||
|
What happens if you just use:
Code:
var myOpener = opener.location.href; MK |
|
#3
|
||||
|
||||
|
Actually, this works equally well:
Opener Code:
<html>
<head>
<title>PopUp 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
Create popup window <a href="#" onClick="MM_openBrWindow('pop2.html','PopUp','width=250,hei ght=250')">here</a>
</body>
</html>
Popup Code:
<html> <head> <title>PopUp 2</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <div id="Wrapper"></div> <script language="JavaScript">Wrapper.innerHTML=opener.location;</script> </body> </html> MK |
|
#4
|
|||
|
|||
|
No, it still doesn't work. Thanks though!
Tony |
|
#5
|
||||
|
||||
|
Yep - it won't work across domains by the looks of things. This appears to be "by design" in order to protect cross-frame security
MK |
|
#6
|
|||
|
|||
|
[QUOTE=selwonk]Actually, this works equally well:
still not working, what could be the problem? Tony |
|
#7
|
||||
|
||||
|
Quote:
I don't think you can do it. You might try adding the URL to a field in the original page and then trying to read it? MK |
|
#8
|
||||
|
||||
|
Quote:
Nope - cross-domain security appears to stop you doing this as well MK |
|
#9
|
|||
|
|||
|
Quote:
Yeah, I think that is the case. Thanks a lot guys. Tony |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > using window.opner in jscript problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|