Web Analytics Made Easy -
StatCounter variable = window.open - CodingForum

Announcement

Collapse
No announcement yet.

variable = window.open

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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?
    Be yourself. No one else is as qualified.

    Comment

    Working...
    X