Refreshing page with window.location.reload() in chrome is causing issue [duplicate] - javascript

This question already has answers here:
JavaScript location.reload() is losing post data
(7 answers)
Closed 8 years ago.
In Chrome whenever i try to refresh a page with button click i'm losing all the posted data on that page.
For e.g.
I navigate from Page 1 to Page 2 and pass some data to Page 2 from Page 1. Now when i refresh Page 2 with any of the following lines of the codes:
history.go(0);
OR
window.location.reload();
OR
window.location = window.location.href
After Page 2 is refreshed i loose all the data that i got from Page 1.
This is only happening in chrome. In Firefox and IE 8 after refreshing Page 2 it still has the data which i transferred from Page 1.
Can anyone please guide me on how can i refresh the page without losing the data. Thanks

Do you need to use POST data to load page 2? Try using URL Params to keep the state of your page.
index.html?var1=bla

Related

Hard reload iframe on partent page reload [duplicate]

This question already has answers here:
How to refresh an IFrame using Javascript?
(13 answers)
Closed 5 years ago.
I have a master page which has 2 iframes - which are frequently updated. The problem is when I reload the master page - both of the iframes LOAD from CACHE (Chrome takes the cached versions no matter how much time has passed after the last updates of the iframe content). This is so frustrating. Can I force the master page to load the iframes FROM SERVER each time it is reloaded?
Thank you!
Dave
when you call the page then you add time like this www.example.com/iframe.html?q=201710191034123
Code
var d = new Date();
var iframe = $('#secondPage');
iframe.attr('src','www.yoursite.com/yourpage?g='+d.getTime())

Javascript: Change Url without refreshing the page [duplicate]

This question already has answers here:
How do I modify the URL without reloading the page?
(20 answers)
Closed 8 years ago.
I am in a page with url
https://mysite.com/tst/v1/my-app/var/$%5Btest_new_var%5D.
On click i want to change the url to
https://mysite.com/tst/v1/my-app/" without reloading the page.
How can i do that?
please help,
Thanks.
In newer browsers that support history.pushState you can replace the url without reloading.
Lets say a user browses to http://example.com/ernie.html
window.history.pushState({ foo: "bar" }, "page 2", "bert.html");
Will change the address bar to http://example.com/bert.html, but won't cause the browser to load bert.html or even check that bert.html exists.

Is there any way to define back/forward button effects on a web page? [duplicate]

This question already has answers here:
Javascript : Change the function of the browser's back button
(5 answers)
Closed 8 years ago.
I have a page where the content is delivered mostly though javascript. Hitting the back button would basically exit the page to wherever the user came from instead of showing the previous content. Is there a way to take manual control over what the back/forwards buttons do on a web page?
This is a classic AJAX problem - each page is loaded asynchronously with no new GET from the browser, thus no history.
Look into History API of HTML5 to programatically push page state into the browser history. Other than that you are out of luck.

hit f5 or refresh button on page should not call last event [duplicate]

This question already has answers here:
prevent duplicate data in reload page after submit form [duplicate]
(2 answers)
How to prevent duplicate posts via a browser refresh? [closed]
(4 answers)
Closed 9 years ago.
I am trying to insert image into database and after saving one image, I want to hit f5 or refresh buttton in browser, but the same image is inserted at that time please give me solution for this.
Looks like you have to make redirect instead of posting content to the same site.
It would go something like this:
Site with form -> post content -> site saving file -> site with form
Where I think you are doing something like:
Site with form -> post content -> site with form
Few ways to protect yourself against inserting the data twice.
The best way is your data was stored then redirect to confirmation page , Like
protected void btnSavebutton_Click(object sender, EventArgs e)
{
ItemsSaved();
Response.Redirect("confirmation.aspx");
}
More details, see this previous discussion

How to refresh and Reload the pages using javascript? [duplicate]

This question already has answers here:
Javascript refresh page
(3 answers)
Closed 10 years ago.
I have one requirement.i.e. Have one login form contains username and password,once we entered wrong password, it navigates to another page(Error message page) and I clicked the browser back button for previous page(login page).Now my page is refreshing,but I need page Reloading.Can you please help me how to reload the page.
Thanks.
$('#hello').click(function() {
location.reload();
});

Categories