history.back(); doesn't trigger $(document).ready();

可紊 提交于 2019-11-29 05:39:04

A quick solution to this problem, use "onpageshow" instead.

window.onpageshow = function(event) {
    //do something
};

If the user uses the Back button to navigate and you require a full reload of the page, you can set the NO-CACHE policy of the page.

This way the browser is forced to reload the page from the server, even using the Back button.

1.) put scripts at the bottom of your page.
2.) execute plugins and whatnot in your last script tag(s).
3.) Do not use onDomReady implementations at all, it's redundant.

People are so accustomed to onload or ondomready, they overlook the fact that putting your scripts at the bottom of a page does virtually the same thing without the need to poll and see if your html is available.

Furthermore, it's also good practise as your scripts do not block html/css rendering either.

Not depending on onDomReady or onLoad implementations solves a lot of issues.

Very interesting question. You might need to re-trigger the event/function when the page gets focus, or something similar. you might also need to keep a flag variable to track whether an 'event re-triggering' is in order.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!