Solved

window.opener issue

Posted on 2003-11-26
16
15,019 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
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
Comment Utility
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
Comment Utility
@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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 21

Author Comment

by:ap_sajith
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks, glad you found my input useful
0
 
LVL 10

Expert Comment

by:NetGroove
Comment Utility
Thamks for the points.
0
 
LVL 21

Author Comment

by:ap_sajith
Comment Utility
you guys deserve it.. thanks a lot..

Cheers!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now