JavaScript Stop loading on href [duplicate] - javascript

This question already has answers here:
Can I cancel location.href in Javascript
(2 answers)
Closed 3 years ago.
I want to redirect a user using window.location.href and I want to stop it at anytime.
I tried:
window.location.href = "https://stackoverflow.com"; //Redirect
window.location.href = ""; //Stop Redirecting
Is this even possible?

Once you redirect the user to the new page, any scripts currently running will be stopped. Thus you cannot "stop" a redirect once you've committed to it.

Related

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.

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

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

New page is not relacing the existing parent page [duplicate]

This question already has answers here:
Redirect parent window from an iframe action
(14 answers)
Closed 9 years ago.
I have a html page and on GO button i have write redirecting code
window.location.replace(url);
I put this page in iframe and on click on GO button result page should open in the existing page replacing the url of the browser but it is opning in iframe only...
I tried
<base target="_parent" /> also but no luck
window.top.location.href is what you're looking for.
Your result page needs to break out of the iframe:
http://www.w3schools.com/js/tryit.asp?filename=tryjs_breakout

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