Reputation: 65978
How can I run below method without any action only once.I mean need to call below method on my page load due to one of my plugin is not bind properly without F5.So How can I achieve that ?
location.reload();
Upvotes: 2
Views: 1491
Reputation: 13544
Indeed there are many ways to get what you need. There is cookies for example. However, in this answer I will explain more simple way. It is using an iframe
.
The solution depends on that your main page will be an iframe from reloading page. Suppose we have to pages: main.html and loader.html.
Don't get confused, loader.html is going to be the page that we access from the browser
<!-- loader.html -->
<html>
<head>
<title>loader</title>
</head>
<body>
<iframe src="main.html" name="toLoad"></iframe>
<script>
toLoad.location.reload()
</script>
</body>
</html>
Some CSS will styling your loader.html and its iframe to make it covering well.
Upvotes: 0
Reputation: 27853
If you really want to do that, you can set a flag in any persistent medium you want (like localStorage, cookies, etc):
if (sessionStorage.getItem('pluginBugFixedByReloading') !== 'fixed' {
sessionStorage.setItem('pluginBugFixedByReloading', 'fixed');
location.reload();
}
Here is a link about some kinds of storage: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage
Before you do this, you should ask yourself: why isn't the plugin working without a refresh? Should i wait for the end of some asynchronous operation before i do something?
I don't know the details of your situation, but reloading the page seems like a very ugly hack that will probably backfire in unexpected circumstances.
Upvotes: 3