SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Window problem......

    I have been tasked with creating a popup warning window for my day job. I was able to find some dhtml code that does this quite nicely, however, I cannot get it to do 1 task that is needed. If the user does not agree with the terms, then they are sent somewhere else.

    I have posted both pages below if anyone can help. Both pages are Cold Fusion pages with some JS mixed in.

    Can anyone offer any help?

    Thanks

    Chris

    PHP Code:
    Page 1:

    <
    html>
    <
    head>
        <
    title>WARNING! FOR OFFICIAL USE ONLY</title>
    <
    script>
    // set the popup window width and height
    var windowW=500 // wide
    var windowH=550 // high

    // set the screen position where the popup should appear
    var windowX = (screen.width/2)-(windowW/2);
    var 
    windowY = (screen.height/2)-(windowH/2);

    // set the url of the page to show in the popup

    var urlPop "warning_banner.cfm"

    // set the title of the page

    var title =  "WARNING! FOR OFFICIAL USE ONLY"

    // set this to true if the popup should close
    // upon leaving the launching page; else, false

    var autoclose true

    // ============================
    // do not edit below this line
    // ============================

    "width="+windowW+",height="+windowH;
    var 
    beIE document.all?true:false

    function openFrameless(){
      if (
    beIE){
        
    NFW window.open("","popFrameless","fullscreen,"+s)     
        
    NFW.blur()
        
    window.focus()       
        
    NFW.resizeTo(windowW,windowH)
        
    NFW.moveTo(windowX,windowY)
        var 
    frameString=""+
    "<html>"+
    "<head>"+
    "<title>"+title+"</title>"+
    "</head>"+
    "<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
    "<frame name='top' src='"+urlPop+"' scrolling=auto>"+
    "<frame name='bottom' src='about:blank' scrolling='no'>"+
    "</frameset>"+
    "</html>"
        
    NFW.document.open();
        
    NFW.document.write(frameString)
        
    NFW.document.close()
      } else {
        
    NFW=window.open(urlPop,"popFrameless","scrollbars,"+s)
        
    NFW.blur()
        
    window.focus() 
        
    NFW.resizeTo(windowW,windowH)
        
    NFW.moveTo(windowX,windowY)
      }   
      
    NFW.focus()   
      if (
    autoclose){
        
    window.onunload = function(){NFW.close()}
      }
    }

    function 
    Declined_click(){
        
    window.location('http://www.usps.com');
    }
    </script>
    </head>

    <body onload="openFrameless()">
    <a href="javascript:openFrameless()">click here</a>
    </body>
    </html> 
    PHP Code:
    Page 2:

    <
    cfsetting showdebugoutput "no">

    <
    cfif IsDefined("agree") and agree eq 'y'>
    <!--- 
    What happens here? --->
    <!--- 
    Set accepted session cookie --->
    <!--- 
    Close Window --->
    <
    script>
    top.window.close();
    </script>
    <cfelseif  IsDefined("agree") and agree eq 'n'>
    <!--- What happens here? --->
    <!--- Close Window --->
    <!--- Force the user to go to X URL --->
    <script>
    alert('You are supposed to go somewhere now.  But it\'s not working. :(');
    //window.opener.execScript('Declined_click()', 'javascript');
    top.window.close();
    </script>

    </cfif>

    <html>
    <head>
        <title>WARNING! FOR OFFICIAL USE ONLY</title>
    <style>
    body{
    border: 4px solid #000000;
    }
    </style>
    <script>
    function stayontop(){ //Brings the current window on top of others
        self.focus();
        setTimeout("stayontop()", 1000); //1000 = 1 sec
    }
    </script>
    </head>
    <body>
    <br>
    <table cellspacing="0" cellpadding="0" border="0" align="center">
    <tr>
    <td colspan="2">
    <font face="Helvetica, verdana, arial">
    <center><b>WARNING! FOR OFFICIAL USE ONLY</b></center><br><br>
    This is a U.S. Government computer system and is intended<br>
    for official and other authorized use only.  Unauthorized access<br>
    or use of this system may subject violators to administrative<br>
    action, civil, and/or criminal prosecution under the United<br>
    States Criminal Code (Title 18 U.S.C &sect; 1030).<br><br>

    All information on this computer system may be monitored,<br>
    intercepted, recorded, read, copied, or captured and disclosed<br>
    by and to authorized personnel for official purposes, including<br>
    criminal prosecution.  <b>You have no expectations of privacy<br>
    using this system.</b><br><br>

    Any authorized or unauthorized use of this computer system<br>
    signifies consent to and comploance with postal service policies<br>
    and these terms.<br><br></font>
    </td>
    </tr>
    <tr>
    <td align="center"><font face="Helvetica, verdana, arial"><a href="./warning_banner.cfm?agree=y" target="_self">I agree</a></font></td>
    <td align="center"><font face="Helvetica, verdana, arial"><a href="./warning_banner.cfm?agree=n" target="_self" onClick>I disagree</a></font></td>
    </tr>
    </table>
    </body>
    </html> 

  2. #2
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the user does not agree try calling the following before closing the popup window:
    Code:
    top.window.parent.location.href = 'http://www.whereiwantyou.com';
    This should change the location of the main browser window to the URL that you specify. Note that I haven't tested this so it may need a bit of fiddling (such as removing the 'top.' portion, for instance).

    - Marshall

  3. #3
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope. Didn't work. Tried playing with the top part, but it didn't work.

    Chris

  4. #4
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... how about
    Code:
    alert(top.window.parent)
    to see if the object exists?

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I may be offbase here (cf always makes my eye blurry But....

    if you are trying to close the original window (based on a 'disagree'), the code should read:

    opener.....close();

    since the 'opener' is the original window.

    'top.window.parent', imho, bad syntax. 1) you should never need to say 'window', 'top' & 'parent' refer to frames. Even if your original page is in frames, you would say something like:

    opener.top....close()

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  6. #6
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks all. I ended up scraping this for a non-chromeless version that was easier to edit.

    Thanks again.

    Chris

  7. #7
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vincent - The reason I chose "top.window" is because of this line in the original source code:
    Code:
    top.window.close();
    Since this line supposedly worked it made sense to use a derivative of this format to target the parent, since parent is a property of the window class. *shrug*

    - Marshall


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
  •