I was wondering what the best way was to detect when a page has finished loading, where the page in question is in a different tab or window, ... and where page to be loaded could be any page on the web and is not under my control.
I am using Firefox only and I don't mind if the solution requires a Firefox extension or Grease Monkey script (I have already added the configuration/commands to allow access to pages from different domains).
The code below shows an attempt. It sometimes detects when the initial page has loaded but when I press 'submit' to reload a new page into the other window, it doesn't detect it.
Thanks.
<html>
<head>
<script type="text/javascript">
currentPageObj = window.open("http://www.bbc.co.uk", "currentPage");
currentPageObj.addEventListener("load", function(){alert("loaded")}, false);
</script>
</head>
<body>
<form action="http://www.example.com" target="currentPage">
<input type="submit">
</form>
</body>
</html>
In the other page just have an onload event handler which calls a method in the parent window (window.opener
) to do what you want. e.g. in the child page:
window.addEventListener('load', function () {
if (window.opener && !window.opener.closed) {
window.opener.childLoaded();
}
}, false);
And have childLoad do what you want in the parent window. (Note: it might be best to keep a reference to the window you want to deal with e.g. initialise var parentWindow = window;
because when you call between windows this can get confusing.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With