SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast pff's Avatar
    Join Date
    Dec 2000
    Location
    Google PageRank: 6
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Popup Once Centered

    Hello,
    I have one code for popup once and one for popup centered. I want to combine these two scripts so that it will popup once centered, but since I know nothing about JavaScripts, I can't do it. Any help will be greatly appreciated. Here are the codes:

    Popup centered:
    Code:
    function NewWindow(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    }
    Popup once:
    Code:
    var expDays = 1; // number of days the cookie should last
    
    var page = "only-popup-once.html";
    var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
    
    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);
       }
    }
    Last edited by pff; Oct 28, 2001 at 16:30.
    pff | I am not what I am

    'Does he exist in the same way as I exist?'
    'You do not exist Winston,' said O'Brien.

  2. #2
    SitePoint Zealot jonsteele's Avatar
    Join Date
    Jan 2001
    Location
    Toronto
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Try this:

    Code:
    var expDays = 1; // number of days the cookie should last
    
    mypage
    var myname = "name of window"
    var w = 300 //width
    var h = 400 //height
    scroll = "no"
    var mypage = "only-popup-once.html";
    
    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);
    
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    
    }
    else {
    count++;
    SetCookie('count', count, exp);
       }
    }


Bookmarks

Posting Permissions

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