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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    variable = window.open

    I having trouble with this code, I have this timer running in a js file if the timer runs out then an alert box pops up letting the user know that they have been logged out. There is also a pop-up window and if the user press down on the key board then the timer resets. I have already done this in my test files, What I am trying to do is apply it to this other code and its a bit tricky. Below you will find my test code.

    test1.php

    PHP Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" language="javascript">
    var test2
    function popup() {
    test2=window.open( "test2.php", "myWindow", 
    "status = 1, height = 300, width = 300, resizable = 0" )
    }

    </script>
    </head>

    <body>

    <?php
    echo '<a href="#" onclick="popup()" >Click Here</a>';

    echo 
    '<embed src="logout_operator.wav" autostart="false" id="logout" width="0" height="1" loop="false">';
    echo 
    '<script type="text/javascript" language="javascript" src="test.js"></script>';
    echo 
    '<script type="text/javascript" language="javascript">
    function timeout(logoutSound)
    {
        var soundLogout=document.getElementById(logoutSound);
        soundLogout.Play();
        alert("Your session is expired please login again");
        location = "http://www.google.com";
    }
    </script>'
    ;
    ?>
    </body>
    </html>
    test2.php (pop-up window)

    PHP Code:
    <head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <
    title>Untitled Document</title>
    <
    script type="text/javascript" language="javascript" src="test.js"></script>
    </head>

    <body>
    <script type="text/javascript" language="javascript">
    window.onkeydown = handle;

    function handle() {
    resetTimer();
    return true;
    }
    </script>
    </body>
    </html> 
    test.js

    Code:
    var timer = setTimeout("timeout('logout')", 5000);
    
    function resetTimer(d) {
    clearTimeout(timer);
    if (d!="done"){
    if (location.href.indexOf("test2.php")!=-1){
    window.opener.window.resetTimer("done");
    }
    else{
    test2.window.resetTimer("done");
    }
    }
    timer = setTimeout("timeout('logout')", 5000);
    }
    What I am trying to do is apply the function and the button to this code:

    Code:
    var _h = {
        mi: function (link, title, ni, qi, width, height, ri) {
            return '<a href="' + link + '"' + (ri != null ? ' class="' + ri + '"' : '') + ' target="_blank" title="' + title + '" onclick="this.newWindow = window.open(\'' + link + '\', \'' + ni + '\', \'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=' + width + ',height=' + height + ',resizable=1\');this.newWindow.focus();this.newWindow.opener=window;return false;">' + qi + '</a>';
        }
    I have tried to put the test2 variable as _h but that didn't work at all. Any help would be much appreciated, thanks!!!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Ummm...fatal flaw: You are including "test.js" in both the main page and the popup page, right? So in *BOTH* pages you are doing a setTimeout. But in the popup, you'll get an error when the timer expires because the popup doesn't have the timeout(logoutSound) function defined.

    I suppose it won't hurt, but it makes me suspicious of the rest of it.

    Seems overly complex.

    Anyway, I don't understand this part, at all: "I have tried to put the test2 variable as _h..." Huh? What do the two variables have to do with each other?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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