Reputation: 312
I want this code top.location.href= 'http://myweb.com/super-minimal-page.html';
only target devices that take a long time to load my page (maybe more than 12 second still not full loading my page).
Upvotes: 2
Views: 597
Reputation: 1401
Make Boolean
variable is loaded with false value on the top of your script
then create setTimeout
function for 12 secound that refare to function you need to fire in case of the page is not loaded
in the document.load function set the Boolean variable to true and check for the variable in your pageNotLoaded function as below
<script type="text/javascript">
var pageIsLoaded = false;
setTimeout(PageNotLoaded, 12000);
$(function(){
pageIsLoaded = true;
});
function PageNotLoaded()
{
if(!pageIsLoaded)
{
// do your code here
}
}
</script>
Upvotes: 1
Reputation:
document.readyState
will return "complete"
when the page has finished loading. You can set a timeout and check if the value of readyState
isn't "complete"
after 12 seconds.
setTimeout(function () {
// Not complete. Document hasn't finished loading.
if (document.readyState !== 'complete') {
top.location.href = 'http://myweb.com/super-minimal-page.html';
}
}, 12000);
Upvotes: 4