Forum Moderators: open

Message Too Old, No Replies

Making a window load into itself

         

stcrim

2:58 am on Apr 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a way to insure that when the script below makes a pop-behind that if the same code is one another site, the window re-fills rather than making a new window? In other words I don't want to have a lot of windows opening, but I do want the content of the window to change if someone hits the script on another page or site of mine.

-s-

<script>
function GetCookie() {
var cookiecontent = '';
if(document.cookie.length > 1) {
var cookiename = 'WINDOW325=';
var cookiebegin = document.cookie.indexOf(cookiename);
var cookieend = 1;
if(cookiebegin > -1) {
cookiebegin += cookiename.length;
cookieend = document.cookie.indexOf(";",cookiebegin);
if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
cookiecontent = document.cookie.substring(cookiebegin,cookieend);
}
}
return cookiecontent;
}

function PutCookie(d) {
var exp = '0';
if(d > 0) {
var now = new Date();
then = now.getTime() + (d * 24 * 60 * 60 * 1000);
now.setTime(then);
exp = '; expires=' + now.toGMTString();
}
document.cookie = 'WINDOW325=yes; path=/' + exp;
}

function WINDOW325() {
var mycookie = GetCookie();
if(mycookie == 'yes') { return; }
PutCookie(0);
var WINDOW325 = window.open('http://www.mysite.com/NoNonSense/myfolder/index.html','','scrollbars=yes,height=565,width=615,resizable=yes');
self.focus();
}
setTimeout("WINDOW325()",0);
// -->
</script>

Rambo Tribble

3:47 am on Apr 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure I understand. If someone loads one of your pages, it will load in the current browser window, unless you are controlling the load from a link on one of your other pages. If they are using a link on one of your pages, you already control where that goes and whether it creates another window.

Do you mean you want to target subsequent links to a window opened by a previous link? In that case you should be able to test with and if() statement whether the window already exists and target the load accordingly. Rather than opening the window directly, open it by assigning it to a variable then test for the existence of the variable.

ajkimoto

4:55 am on Apr 9, 2004 (gmt 0)

10+ Year Member



stcrim,

Just set the second parameter of the window.open function to a string--this assigns a name to the popup window and will keep you from spawning a new window each time. Rather, the same window is reused. Here I have assigned the window the name indexWindow:

var WINDOW325 = window.open('http://www.mysite.com/NoNonSense/myfolder/index.html','indexWindow','scrollbars=yes,height=565,width=615,resizable=yes');

ajkimoto