简体   繁体   中英

How to make a window.onload event fire without reloading the page javascript

I am wondering if it is possible to cause a window.onload event to occur without reloading the page. I want to use this becuase I am using ajax to load new pages, however this ajax load method doesn't make the window.onload event fire.

Right now I am using:

location.reload(); 

But this causes the whole page to reload.

Thanks

I am not sure what is the purpose here, but let's assume you have this:

window.onload = function() {...};

You could do this instead:

var bootstrap = function() {...}
window.onload = bootstrap;

then in other part of your code, where you want to simulate the onload , just call bootstrap function by yourself.

Inside your call back function you might say,

window.location.href = 'correctpath_here';

Or

window.location.reload = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM