I’ve been making a webpage that uses a sort of… external survey taking. I was wonder if when using the window.open method, can you tell if your new window had a 404 or the page timedout trying to load?
Here is what I have so far:
child = window.open(href, 'window');
setTimeout(function() {
// Do some backend processing if child window is still open and no 404 / timeout
}, 10000);
That’s a pretty hard thing to do. You have to deal with security issues (cross domain access is forbidden in JS). But I think this function can do the trick:
Explanation: try to access the
locationelement of the child window. If the window has loaded, trying to access it will throw an exception (cross domain JS access is forbidden) so you manage that. But if you can access the location that will probably mean it’s still loading.The main problem is that, with this code, you can only distinguish when it’s loading or not, so I suppose you could only check for timeout. I think that checking 404 error is almost impossible as the JS security restrictions don’t allow you to get the location or content of an external page.