How to stop page reload or refresh while I come back from view page.I am using back button where I call java script history.Go to get back to my page but the page actually got refresh and loss all data.
Related
From a sign up success thanks page I am redirecting to another webpage using window.location object. But after redirecting, clicking browser back button shows the sign up page not the sign up success thanks page. Tried the same scenario without pressing the back button instead used window.history.go(-1) , this works fine it loads the success thanks page itself.
Use window.location.href = 'YOUR LINK'
Right now, you are replacing the current page url (success page) with the new page (redirected page), so when you go back you go to the previous page in the history stack, which is the sign up page.
You can also use history.pushState() to add entries to the location history
If I am on the page http://mywebsite.com/contact and I do:
window.location.assign('http://mywebsite.com/contact#foo');
The page doesn't refresh and I understand thats desired. But I want to refresh/reload the page (to update the users cache). Is there a Javascript or JQuery function that I can use that will change the url and always reload/refresh the page?
Usecase
When a user clicks any anchor html element, my function checks if the page has been reloaded/loaded within the last 24 hours. If it hasn't I will call my javascript function above to ensure the user navigates to their desired page but also reloads the whole page to ensure they are working with the latest version of the Single Page Application.
Just put window.location.reload(true); after window.location.assign()
window.location.reload(true) will reload the page from the server.
window.location.reload(false) will reload from cache, if available.
I am getting data properly from the database and displayed in the JSP page for the first time. When I Refresh the page the page appears blank and continue to show blank data even I refresh again and again. To get proper data, I had to close and open the JSP page in a new window. What is the problem?. I am using tomcat Server.
I have an HTML page. Everytime I add new content to the page, the user needs to refresh the page in order to see the new content.
What I want to do is to refresh the page automatically for them regardless of browser.
I tried putting the following but the screen flickers so many times that it does not prove to be useful:
<script type="text/javascript">
location.reload();
</script>
The JavaScript you show there does indeed reload the page. Every single time the page loads, as soon as it reaches that JavaScript. The flickering you're seeing is probably the fact that it in an infinite cycle of reloading. What you need to do is perform an AJAX request to the server to find out if there is new content, and then reload the page if there is. Or, alternatively, use the AJAX to actually update the new content on the page.
I have a widget which is embedded in random sites. when the user clicks I call the server to update the click occured and the server returns redirect to the correct page. The problem is that the Back button of the browser no longer works.
I use location.href for the redirect.
I tried location.replace -which keeps the back button , but it goes to the page before the page in which the widget was clicked (it replaces it with the new page).
How can I do the page switch after reporting to the server and still allow the back button to work?
You cannot go back to a page that auto-redirects. That's just a broken back button and a frustrated user.
User goes to page A.
User clicks on link to page B.
Page B automatically redirects to page C with window.location.
User hits back button and momentarily goes back to page B.
Page B automatically redirects to page C with window.location.
User hits back button and momentarily goes back to page B.
Page B automatically redirects to page C with window.location.
User is sad.
Obviously this doesn't work. It has to work like this instead:
User goes to page A.
User clicks on link to page B.
Page B automatically redirects to page C with window.location.replace().
User hits back button and goes back to page A.
User is happy.
You must auto-redirect with window.location.replace() if you want the back button to work.