Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop up window and handler

Status
Not open for further replies.

iMediaX

Programmer
Jul 27, 2003
4
AU
Hi Guys

Another beginner questions (sorry!). I have the following pages setup:

Page1.asp (parent window)
Page2.asp (parent window)
PopupPage.asp (child window)

Page1.asp has a form which when submit will open a new window displaying PopupPage.asp.

On the PopupPage.asp, depending on the values selected from the form, a table is shown with rows of data returned from SQL query. Now one column of each row contains a hyperlink. And upon clicking the hyperlink will force the parent window to load Page2.asp. PopupPage.asp (child window) still open and will be until it is closed).

The problem I am having is that on Page2.asp, there is a Back button which when click takes user back to Page1.asp. I want to close the PopupPage.asp ie the Child window when this Back button is clicked. However, when I do the following in Page2.asp:

if (formWin && !formWin.closed) {
formWin.close();
}

It wont work. "formWin" is the name i give to the child window.

Is this because the handler for the child window is lost once I load a new page ie Page2.asp in the parent window? So does this mean I need to pass the handler from page1.asp to page2.asp?

Any solutions are highly appreciated!! Again i am a beginner so please go easy on me.

Thanks for your help

Regards

Kevin


 
>> Is this because the handler for the child window is lost once I load a new page ie Page2.asp in the parent window?

Yep.

>> So does this mean I need to pass the handler from page1.asp to page2.asp?

Sort of... Except that you won't be able to pass it directly from page1 to page2. Communicating between windows like that would require that a) both windows were open at the same time, and b) the two windows were somehow related to each other.

What you will need to do is use your popup to periodically check the location object of the opening window (it still has an inbuilt handle to [tt]opener[/tt])

When you create the popup, you can assign a variable the value of the opening window's url. Then when you use the popup to change the opening window's location, you can start periodically checking (using setTimeout function) the opening window - if at any time, the check reports that the location reverts back to the original you can close the popup.
 
Thanks so much for your reply.

Just wondering if you dont mind, can you provide me a code sample on what you said above. More specifically, on the setTimeOut function.


Thanks alot

Regards

Kevin
 
Code:
<!-- 
     polling routine to see if opening window has reverted
     back to original URL.

     Place this code in your popup window
-->
<script>
//Holds the original URL of the opening page
var origURL = window.opener.location.href;

//Flag to see if the URL has changed
var hasChanged = false;

//Polling function to examine the opener's URL
function pollOpener(){
 //Get the current URL of the opening window
 var currURL = window.opener.location.href;

 //Check to see if the URL has changed already
 if(hasChanged){

  //If it has, check to see if the new URL is the same
  //as the original
  if(currURL == origURL){

   //If it is, then the user has browsed away from
   //the opening page, then browsed back - we can close
   //this (popup) window
   window.close();
  }
  
  //If it is a different URL from the original, use the 
  //setTimeout function to call this function again in 
  //0.25 seconds
  else{
   setTimeout('pollOpener()',250); //250ms = 0.25s
  }
 }
 
 //If the URL hasn't changed up until now, this is the 
 //first time the user has browsed away from the opening
 //page. Set our hasChanged flag to true
 else{
  hasChanged = true;
  
  //And - using setTimeout - check again in 0.25 seconds
  setTimeout('pollOpener()',250); //250ms = 0.25s
 }
} //End of polling function
</script>

Now, all we need to do is get the ball rolling - we do this by calling the pollOpener function on the document's onload event.
Code:
<body onload=&quot;pollOpener();&quot;>
 
Hi, I hope someone is still linked to this post. Need some help here as i am getting terribly confused. I am using Asp.Net and some javascript with a SQLServer 2000 as my database.

I have 2 pages addDoc.aspx(parent) and DocGetDetails.aspx (child).

At addDoc.aspx, users can enter new document and add it to the database. On this page, there's an image button whereby upon clicking a new browser window(DocGetDetails.aspx) will open and retrieve data previously entered into the database using a variable entered on addDoc.aspx. From here, the user will then select the particular row of data and pass the data back to addDoc.aspx this is to minimise data-entry for the user if it's just a document that has been revised, which means, only the version no needs to be amended and not the description and title.

here's what i have so far:
- I have managed to open up DocGetDetails.aspx together with the variable passed.

my code:

AddDoc.aspx Page Load event

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim strOpen As String
strOpen = &quot;DocGetDetails.aspx?Desc&=&quot; + Session(&quot;DocItem&quot;)
Page.RegisterStartupScript(&quot;startup&quot;, &quot;<script language='javascript'>function OpenIt(){var desc = document.Form1.elements['txtDesc'].value; window.open('DocGetDetails.aspx?Desc&=' + desc, '_blank', 'width=500,height=400,top=50,left=150,location=yes,toolbars=no,scrollbars=yes,status=no,resizable=no');}</script>&quot;)
ImgDesc.Attributes.Add(&quot;OnClick&quot;, &quot;OpenIt()&quot;)

End Sub


DocGetDetails.aspx page load event

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim strDesc As String
strDesc = &quot;'%&quot; + Request.Url.Query.Substring(7) + &quot;%'&quot; '&quot;'%&quot; + Label1.Text + &quot;%'&quot;
Filldata()

End Sub

the burning question i have is how do i pass the data back from DocGetDetails.aspx to addDoc.aspx? I am using datalist to display the data. What I am attempting to do is to let the user select the record and click on a button (on DocGetDetails.aspx) to send the data back to addDoc.aspx

I came across a FAQ - Communicating between two windows, but i am still having some problems getting the hang of it as it uses hidden fields.I would appreciate any help or hints or anything that can point me in the right direction. Thanks heaps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top