0

I have a script that invoke pageLoad after all content is loaded.

I need it to be on before page load

my script is

 function pageLoad()
{
    $('#myModal1').modal('show');
}

window.onload = pageLoad;

Can anyone do anything this script to get show on before load page?

Thanks very much

newbie
  • 29
  • 7
  • You just call the function when you want to call it instead of using it as an load handler. What's the problem? – Quentin Jul 24 '16 at 12:45
  • "How what?". *How do you call a function?* The code you've written already includes two examples of calling functions directly. (And if you don't know how to call a function then you really need to be reading an introductory JS tutorial and not asking questions on Stackoverflow). *How do you know when to call the function?*. I don't know when you want to call it. There are lots of times that you could call it before the load event fires. You haven't sufficiently described your problem for anyone to determine which would be appropriate. – Quentin Jul 24 '16 at 12:49
  • i have a pop up which plays autoplay video, on opening page ,its not poping and plasy sound only...bcos that waits to wait full content load...how to fix this... – newbie Jul 24 '16 at 12:56
  • Your question needs a [MCVE] (and you probably need to focus on [the actual problem rather then the solution you think will fix it but can't get working](http://xyproblem.info/)) – Quentin Jul 24 '16 at 12:57
  • When someone tells you that they need more information before they can help you, then it's a pretty good indication that they can't give you an answer yet. Being rude to them is a good way to discourage them from answering if you ever bother to edit your question to make it easier to answer. – Quentin Jul 24 '16 at 13:01
  • You know any script , where a pop up that load before the page load..that only i want...and i dont know why you still understand situation..other legends answered and working fine.....but your downvoting doesnt indicates you are going to answer...you only showing you reputation – newbie Jul 24 '16 at 13:05

1 Answers1

2

The onreadystatechange event is fired on a HTML document when the load state of the page's content has changed.

document.onreadystatechange = function()
{
    console.log(document.readyState);
    if (document.readyState === 'complete')
    {
        console.log("onbefore")
    }
};
window.onload = function(e)
{
  console.log("onload");
};
rejo
  • 3,352
  • 5
  • 27
  • 34