简体   繁体   中英

How to change target url of browser's back button

Thanks for attention. I searched blow question from a lot of sources but I have not found the correct answer yet. So I hope you all will help me to resolve it. If my question is same to some, forgive me please!

My question is "How to change target url of browser's back button" somethings like that:

$(browser_back_btn).click(function () {
      $(this).targetUrl = $(this).targetUrl + "#abcxyz";
})

Thanks for help!

This is a pretty interesting question.

In javascript you have the object

window.history

What you could do is replaceTheState of the history when you click on the link to your actual page.

Like : window.history.replaceState( {}, '', '/google.com');

If you try as you've said in a comment to check wether or not the user used the back button to access the page. You just have to populate the {} and check for it in the load of the page.

For exemple : window.history.replaceState( {backButtonPresse : true}, 'wtv', location.pathname);

The best thing to do for you is to have a look at this from Mozilla .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM