$(document).ready(function () {
function EndSession() {
window.close();
};
setTimeout("EndSession()", 10000);
});
Shown above is the code in a child page opened using window.open().
The problem is after ten seconds when it tries to call EndSession, it throws an error
“Microsoft JScript runtime error: ‘EndSession’ is undefined”
What is going on here?
Maybe the problem of the old way “string” is that it was looking for the method in the global scope, while the method was defined inside the function used for jQuery
ready.We can explicitly pass the function we really want to, if we have a proper reference to it.
Let’s try:
Although I haven’t tried it, maybe even this will work:
I’m not sure if you need the jQuery ready at all too, unless you intentionally want to start counting time after the document is fully loaded (which I’d expect to be very quick for a pop-up that closes soon).