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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window Manipulation 1

Status
Not open for further replies.

david6633

Programmer
Jul 28, 2003
39
GB
I am yet another newbie to JavaScript but can sometimes manage to find my way around it - so please bear with me.

I have searched through this forum and although there are some similar topics I cannot find one that completely answers my questions.

What I am trying to do is this: I have a page on which there are links and when a user clicks on one of these links a popup window is opened (this I can do) and if the user clicks on another link then it opens in the same popup window (again I can manage this). Here is problem one - on the second, or subsequent link selection the popup window is at the back - how do I keep it on top?

The second part of my problem is that when a user clicks on a link in the popup window how do I get the new page to display in the original window and at the same time close the popup window. I can get it to open in another window and close the popup.

I feel that I am almost there but I am missing something somewhere. Any help would be gratefully appreciated but please remember I am new to javaScript so make it simple!

Many thanks
 
Declare a variable to hold the handle to your popup window in the head of your page, so it can be accessed by all functions:
Code:
var myPopupWin;

When you need to open a new page into the popup window, use this variable to hold the window handle of the popup:
Code:
myPopupWin = window.open('somePage.html','myPopupWin');

To bring the popup window back into focus:
Code:
myPopupWin.focus();

To open a new URL in the original window - from the popup:
Code:
window.opener.location.replace('somePage.html');[/close]

To close the popup window - from the popup:[code]
window.close();

- or from the main window:
Code:
myPopupWin.close();

Hope this helps.
 
Thanks that's great both work - but there is one slight problem: after loading the page in the main window from the popup window if I click on the back button it takes back to the page before the one with the links on that creater the popup window - if that makes sense? Is it possible to make it so that clicking on the back button will take me back to the requesting page?

David
Remember: You only know what you know
and - you don't know what you don't know!
 
Sure... That's one of the side effects of the window.replace() function. To get around it - where I told you to use:
Code:
window.opener.location.replace('somePage.html');

Use:
Code:
window.opener.location.href = 'somePage.html');
 
That's the answer - great

Many thanks for your help - I will go off and try to find some more problems (and as Arnie said "I will return")

David
Remember: You only know what you know
and - you don't know what you don't know!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top