Javascript previous URL after pressing browser back button - javascript

I am not very experienced with Javascript and i have implement simple redirection with Javascript but now i want to get URL (previous) when the user will press browser back button after that redirection.
I am trying to get previous URL with "document.referrer" but it is not returning correct previous url.
I am redirecting my web page with this.
window.open('https://weather.com');
But after this redirection when the user will press browser back button, i want to get back this url from my own web page because i want to track that URL and implement some more functionality.
I ll need help to complete this process and i will really appreciate your help.
Thank you!!

Related

Redirecting to previous page after login in HTML (or Javascript)

I have been searching in a lot of places for answer to this.
What I want is when I go on a page, it redirects the page to the password page, but when I try to get it back, it just redirects back onto the previous page. Maybe use javascript to say "only redirect when there is a part in that code? Any ideas?

Reloading page without browser knowing

I currently am building a website that fetchs data from MySQL with php and then displays it. On one of the pages I use a form to submit data and then I reload the page to display it. It does it's job fine and works exactly as I want the only problem is when a user presses the browser back button it goes through all previously submitted data instead of just going back to the page it came from. Is there a way to reload a page without the browser storing it or is there a way to make the browser go back to the previous page instead of history.
NOTE: I am aware of Ajax and how to use it to not reload the page at all but I wanted to see if there was a way to do it without redesigning my whole page with a seemingly small problem.
You can use history.replaceState in HTML5.
Another possibility appears to be
window.onpopstate = function(event) {
window.history.go(-1);
};
although I have not tried this myself.
See https://developer.mozilla.org/en-US/docs/Web/API/History_API and https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate

JS back button with default page

Hi I'm wondering if there is a way to give window.history.go(-1) a default back page? If you enter a page directly from another site and someone clicks the back button, I don't want to direct them back to the referring site, I'd rather redirect them back to a search page within my application. I notice on some sites they are somehow reading the previous session, is that an option or no? Thanks
may be try something like this:
Back
I think you might be interested in the window onbeforeunload event.
Have a look at this thread: using onbeforeunload event, url change on selecting stay on this page

how to get redirecting page url using javascript

I want to get a url of the page where user is going after reaching to my webpage. Let say user just came to my website page xyz and now he entered the another url abc on the browser bar. So now i want to get a link of abc using jquery or javascript. Is it possible?
Because it can't be done. The new location is private/sensitive information. Nobody wants you to know which sites they visit when they leave your site.
How can i get the destination url in javascript onbeforeunload event?
But if you want to do something before unload than you can get help from below link.
jquery beforeunload does not display message
You got help from this
$(window).on('unload', function(){
});

History Sensitive Back Button

Is it possible to have a button on a webpage that will be named 'Back' and do window.history.back() if the user has navigated to the page from another page on your website and otherwise have some other title and be a direct link if the user navigated to your page from another website or went to the page directly.
Google plus on mobile seems to have this behaviour. When you click on a post in your stream then it has a 'back' button on the post page. However, if you go to the post page directly then it has a 'stream' button on the post page.
This seems tricky to implement because you don't have access to the urls in window.history.
Have you any chance of adding an ext lib like BBQ? It's a package used to manage the history behavior in your page.
I have done this before. You can do this with an anchor in the link. The anchor needs to have every get parameter of your application (i.e. application state) stored. Your application should be able to parse the anchor. To intercept the back button look here: stackoverflow.com/questions/136937/is-there-a-way-to-catch-the-back-button-event-in-javascript.
#benmmurphy I also had the same problem, then I used the following, which worked perfectly for me. You have to paste it on the page, from where you want to go back.
GO BACK
Hope this will help you.

Categories

Resources