Click to See Complete Forum and Search --> : window opener or open window if not open window?


Josefu
08-11-2003, 05:27 AM
Greetings to all, I have been reading from time to time (grin) but this is my first time posting. I have a bit of a dumb problem and was wondering if anyone here could help me out...

My site (in my profile) has a link on every page which can open a new sitemap window. Now, this new window allows the user to click on an image of the page ('room') he wants to go to and that page will open in the the main window (I just used the "opener.location.href= url;" function) - works fine.

BUT - if anyone bookmarks the sitemap page, or comes directly to the sitemap from a SE listing, they can't open a new window from it... I attributed the name 'BigWindow' to my main window which usually opens the sitemap page, I tried all sorts of identifying scripts to check if it's open and if not open a new window (under, if possible) the sitemap but to no avail. The best I could get was a new window even if one main window was already open.

A bit newbie-ish, my problem? Well I am, sort of...

Thanks in advance for any help, take care,

Josefu.

Khalid Ali
08-11-2003, 08:13 AM
suppose your popup window handle is

pop = window.open()

now to make sure its still open

if(!pop.closed){
//not closed
}else{
//closed
}

Josefu
08-11-2003, 08:23 AM
Perhaps I made it sound more complicated than it is. Imagine that you have a main window open a pop-up, and that pop-up can control the main window. That in itself is not hard to do and I have done it already and it's working fine : )

So what can you do if you open up the pop-up directly (from its direct URL. eg) and there's no main window to control? I would like to create a new 'main window' (optimally using the same javascript function that opens the main window in the first place). And control it using the pop-up (as if it was opened from the main window) afterwards.

Hee, sorry for the brouillon.

Take care, thanks,

Josefu.

requestcode
08-11-2003, 09:00 AM
You could have a script in the head section of your Popup that would check for the existance of "opener". If it is present then it does nothing, but if it is not present then it could redirect them to your main document. Here is the code:
<script language="JavaScript">
function check_opener()
{
if(!opener)
{location.href="main_page.html"}
}
</script>

<body onLoad="check_opener()">

Josefu
08-13-2003, 05:44 AM
Great! I get the idea... but the page 'opener' can be any page in my site, as the sitemap is accessible from anywhere.

The main window is a fullscreen chromeless window opened from the index page; in the javascript opening action I gave the main window the name 'bigmain' - will this nams stick even if its content changes? If so, could I address the window by its name instead of its content?

Thanks a lot for your help, guys : )