After I ask this
I was thinking about this solution:
<li><strong>true</strong> indicates refreshing the page using the browser.</li>
<li><strong>false</strong> indicates refreshing the page using a button.</li>
<li>Inside onclick attribute of the button, I set flag to false and call
window.location.reload()to refresh the page.</li> <li>Inside onload attribute of
<body>tag, I check the flag if it's true switch to
Hometab else switch to
Page1tab where it contains the
<div>tag I want to refresh its contents. After that, set flag to true.*</li> </ul>
But unfortunately it doesn't work and
flag is always true when it comes to onload attribute of
*<sub>My page consistes of many tabs, first one is Home (where it should be shown when refreshing the page using the browser) and second one is Page1 (where it contains the
<div> tag I want to refresh its contents and where it should be shown when refreshing the page using the button)</sub>
The browser is stateless, which means that everything on the page is refreshed each time the page loads.
There are a few ways to store persistant information that you can access between requests:
<li>Store the data you want in a cookie and read it when the page loads</li>
<li>Pass data to the URL and read the current URL (including the data that you passed) when the page loads. For example: Redirect the browser to http://something.com/yourpage.html#flag=true if the user refreshed through the browser or redirect to http://something.com/yourpage.html#flag=false if the user clicked the button. On the onload of the page just read the current URL and see what the flag is.</li>
<li>Use a cookie to create a session and store data on the server (technically this is very similar to the first option except you just store a token on the client and pass it to the server to retrieve data that was stored there)</li>
No. However, you can store the variable's value in a number of ways.
<li>in the url (query string)</li>
<li>hidden element on page set from a session variable.</li>
This sounds like a situation where you could use sessionStorage or localStorage in the browser and if the browser doesn't support that, you could fallback on cookies...
You can persist the data by using cookies, window.name, and window.location.hash key