newbie newbie - 4 months ago 13
Javascript Question

How to pop up some contents before page load javascript

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

Answer

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");
};