Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2002
    Location
    Florida, USA
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I control where pop-under window appears?

    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">

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if it is a popunder, do this to control its position
    Code:
    //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!

  • #3
    New Coder
    Join Date
    Nov 2002
    Location
    Florida, USA
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ";

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, brothercakes way is better because it doesn't move it after the popup is called, i just never think of it.

  • #6
    New Coder
    Join Date
    Nov 2002
    Location
    Florida, USA
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    left=0,top=0, works!

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •