...

View Full Version : How do I control where pop-under window appears?



Fred
01-13-2003, 02:07 AM
With the following pop-under code, I'm not sure how to control where the pop-under appears on the screen. Right now, it pops up too far to the right, partially off the screen.
Fred

<script LANGUAGE="JavaScript">

<!-- Begin
var expDays = 0; // number of days the cookie should last

var page = "subscribe.html";
var windowprops = "width=600,height=400,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);

window.open(page, "", windowprops);

}
else {
count++;
SetCookie('count', count, exp);
}
}
// End -->
</script>


</HEAD>

<BODY OnUnLoad="checkCount()" BGCOLOR="#efefef">

chrismiceli
01-13-2003, 03:39 AM
if it is a popunder, do this to control its position


//this is at the latter half of you code
function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);
//edit to this this
win = window.open(page, "", windowprops);
win.moveTo(0,0); //for upper left corner
win.opener.focus();
//stop editing
}

try it!

Fred
01-13-2003, 04:51 AM
Chris,
I added it in here, towards the bottom of my code

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);

window.open(page, "", windowprops);
win.moveTo(0,0); //for upper left corner
win.opener.focus();

It works, but it's doing something weird. I might have done something wrong. When I test ran the code several times, each time the popup loaded, it is slowly tracking from the upper left side of the screen to the lower right side by about 60 or so pixels upon each reloading, instead of reloading in the exact same spot. I wanted to make it reload on the exact location on the screen each time. It appears it might be setting a cookie in my browser which is causing this gradual precession across the screen. After enough test reloadings, it would in theory eventually popup completely off the screen.
Thank you,
Fred

brothercake
01-13-2003, 11:44 AM
You could add the position directly into the window properties

var windowprops = "left=0,top=0,width=600,height=400,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";

chrismiceli
01-13-2003, 02:19 PM
yes, brothercakes way is better because it doesn't move it after the popup is called, i just never think of it.

Fred
01-13-2003, 04:35 PM
Brothercake,

It looks like your idea did the trick. Upon testing the script several times, the popup indeed loads in the exact same location. I trust this will work in all browsers.

It's amazing how very often in coding, the simpliest solution solves a problem.

Thank you!
Fred



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum