Code: Select all
<!-- Functions/scripts to create/close 2nd window -->
<script type="text/javascript">
var displayWindow;
function openWin()
{
displayWindow = window.open("display.html", "Disply", "fullscreen=yes,left=450,top=250,width=1150");
if (typeof localStorage == 'undefined')
{
document.getElementById("tst").innerHTML = "NO Local Storage";
}
else
{ document.getElementById("tst").innerHTML = "Local Storage";
}
localStorage.setItem("savedWindow", displayWindow);
}
function closeWin()
{
var w;
w = localStorage.getItem("savedWindow");
w = displayWindow;
document.getElementById("tst2").innerHTML = "display is " + w;
w.close(); // Closes the second window
}
</script>
Code: Select all
<!-- open window for graphics -->
<div style='padding-bottom: 10px;'>
<button onclick="openWin()">Create Second window</button> <a href='../doc/CreatenewWindow.html' target='_blank'><img src='./icon/question.gif' height='13' width='12' alt='help Link'></a>
</div>
<!-- close graphics window -->
<div style="margin-top: -18px; margin-left: 120px; float: left">
<form action="#" method="GET">
<input onmousedown ="closeWin()" type=submit value='End Train Thing'> <a href='../doc/EndTrainThing.html' target='_blank'><img src='./icon/question.gif' height='13' width='12' alt='help Link'></a>
</form>
</div>
All works as is except. With the code above if I open the window <Create Second window> and then close the window <End Train Thing> WITHOUT running the simulator (going to a different script) all is fine. In the function openWin() the window object tag is saved in the JavaScript variable displayWindow. In closeWin() displayWindow is moved to the variable w and the second window is closed.
Notice this does not use localStorage.setItem() or localStorage.getItem() AND if I go to the simulator script and return this doesn't work
IF I comment out the the line in closeWin()
Code: Select all
w = displayWindow;
I have tried JavaScript localStorage, sessionStorage and cookies same results. The troubleshooting lines are always
I chose two windows vs frames so that I could move the simulator graphics window to a second screen, leaving room for a "simulator tracing" window and CSS HTML validator I assumed that the window tag held in the JavaScript variable is lost when a different PHP script is started. Script one starts script two, and two returns to one using a version ofLocal Storage
display is [object Window]
Code: Select all
header('Location: train_loop.php');