Solved

window.opener issue

Posted on 2003-11-26
16
15,044 Views
Last Modified: 2012-05-04
Hi all,
I have this problem..

I have this page (home.asp) which opens up a popup, which has clickable links... on clicking the link, i am minimizing the popup and calling a function in the opener window ie, home.asp. The function in the homepage redirects the page to view.asp to view the details. Now the problem starts... i go back to the popup and click the next link... this does no action as the window.opener has changed its location. I even tried adding the function in the home page in view.asp.. but still dosnt pick it...

Any ideas as to how to go about this..

Do let me know if you need any further details..

Thanks to all in advance :o)
Cheers!!
0
Comment
Question by:ap_sajith
  • 6
  • 3
  • 2
  • +4
16 Comments
 
LVL 10

Expert Comment

by:Nushi
ID: 9824238
you can simply redirect the home pag eto the location which opened this pop up.

does it helping you.?
0
 
LVL 21

Author Comment

by:ap_sajith
ID: 9824338
I open the popup from the home page... and then on clicking the link in the pop up, the parent window (currently displaying home.asp) has to be redirected to view.asp. Now i go back to the popup (the parent window currently displays view.asp or any of the other pages the user has navigated to!!) and click on the link again.. now the script in the popup does not recognise the window.opener argument anymore...

Cheers!!
0
 
LVL 25

Assisted Solution

by:James Rodgers
James Rodgers earned 75 total points
ID: 9824342
in the popup, how are you redirecting the parent?

<script>
function redirectParent(strUrl){
   window.opener.location.url="strUrl";
}
</script>

the url submitted to the function will need to be absolute
ie: http://www.someserver.com/page/to/display.ext

and you can have it in a select

<select name="selUrl onchange="if(this.selectedIndex){redirectParent(this.value);}">
   <option value="">--Select a destination</option>
   <option value="http://www.google.com/">Google</option>
   ...
</select>

or in an anchor
<a href="#" onClick="redirectParent('http://www.google.com/'); return false>Google</a>

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 25

Expert Comment

by:James Rodgers
ID: 9824427
typo - forgot to close the onclick

<a href="#" onClick="redirectParent('http://www.google.com/'); return false">Google</a>
0
 
LVL 15

Assisted Solution

by:VincentPuglia
VincentPuglia earned 75 total points
ID: 9824447
Hi,

  You are cutting the connecting link, so the quick answer is no.  If you want to be able to go back to home/opener, there are your options:

1)  have the links open new windows/popups instead of redirecting the home page
2) use frames
3) have the necessary functions within the popup (you seem to be using it as the home page anyway) so that it doesn't have to call the home page. However, the popup still will not recognize view.asp as an opener.

Vinny

0
 
LVL 21

Author Comment

by:ap_sajith
ID: 9824584
@Jester.. That wouldnt work.. anyway.. i cant use absolute URLS as well..

@VincentPuglia, I cant use popups or frames...I tried using the function in the popup itself.. however, the same problem with the window not recognising the parent window arose...

Any other ideas?
Cheers!!
0
 
LVL 3

Assisted Solution

by:Flynnious
Flynnious earned 75 total points
ID: 9824614
Create a variable for the window that opened the popup, in the popup:

<body onLoad="getHandle();return true">

<script language="javascript">
<!--
  var hWnd;

  function getHandle() {
    hWnd = window.opener;
  }
//-->
</script>

This way, you can then use hWnd instead of window.opener to refer to the window below, and if the property or function is available in the other window, it should be accessible from the popup using hWnd.

Note I have no idea whether this will work or not.  Please let me know :)

Flynnious
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9824747
Hi ap_sajith


  Ok, you can't use popups & frames.  & you 'must' redirect the opener.   & you must access view.asp through the popup  (not leaving yourself many choices, huh? :)

Flynnious may have something there:

Try this in the popup :

var viewPage = opener;
viewPage.location = "view.asp"

then in the popup have the functions and try accessing the view.asp with:
alert(viewPage.document.forms[0].name)

Vinny
0
 
LVL 21

Author Comment

by:ap_sajith
ID: 9824817
I'll give these a shot... In the meantime.. if anyone else has anyother ideas, then please post your ideas...

Cheers!!
0
 
LVL 3

Assisted Solution

by:etain
etain earned 75 total points
ID: 9824992
code tested working in ie 6
Script for main1.asp and main2.asp
-----------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
if (window.child == null)
      window.child=window.open('pop.asp', 'childwin', 'width=650,height=300');
</script>
</head>
<body>
</body>
</html>

Script for pop.asp
----------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<Script>
      var p = window.opener
      function redirect(Url)
      {
     p.location=Url;
}
</Script>
</head>
<body>
<a href="#" onClick="redirect('main1.asp'); return false">page1</a>
<a href="#" onClick="redirect('main2.asp'); return false">page2</a>
</body>
</html>

0
 
LVL 10

Accepted Solution

by:
NetGroove earned 200 total points
ID: 9825307
Hello ap_sajith,

I have one idea for you.
The idea will work if you can add in every page that is redirectable from popup this JavaScript line:
<script>
window.name="mainWin";
</script>

If this is possible for you, then it will work.
So you have to add upper windo.name assignment in your home.asp, your view.asp and so on.
In the popup page you have to refetch the main window like this:
<script>
function redirectMainWin(newURL){
   mWin = window.open("", "mainWin");
   mWin.location = newURL;
}
</script>


The second parameter in window.open() has to match to window.name value assigned in your home.asp, view.asp and so on.

Good luck,
NetGroove


0
 
LVL 21

Author Comment

by:ap_sajith
ID: 9825422
Thanks for you input guys.. I think i have solved the problem..

I moved the function used to navigate to the new page from the home page to the topbar include file so that all the pages will heve that function...

<FORM NAME="frmNavigate" METHOD="POST">
<INPUT TYPE="Hidden" NAME="EventID">
</FORM>

<script>
function Navigate(EventID)
      {
      document.frmNavigate.action="viewEvent.asp"
      document.frmNavigate.EventID.value=EventID;
      document.frmNavigate.submit();
      }
</script>

And in the Popup page, i am using..

<script>
function viewEvent(EventID)
{
      window.self.blur();
      window.opener.focus();
      window.opener.Navigate(EventID);

}
</script>

That did the trick... Thanks to all of you who has come up valuable suggestions.. I guess i would split up the points among you guys...

Cheers!!
0
 
LVL 21

Author Comment

by:ap_sajith
ID: 9825485
I am using the form post method rather than the window.navigate method as the popup window is called from a different subfolder and i cannote pass the absolute url. If i used window.navigate, then the url is appended with the pop ups' folder path.. thereby generating a 404 error.

Cheers!!
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9825825
thanks, glad you found my input useful
0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9826304
Thamks for the points.
0
 
LVL 21

Author Comment

by:ap_sajith
ID: 9826395
you guys deserve it.. thanks a lot..

Cheers!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question