...

View Full Version : variable = window.open



jsuske
08-20-2011, 05:20 AM
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


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


<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


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:


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

Old Pedant
08-20-2011, 08:17 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum