Page 1 of 1

[SOLVED] Click link; then go back

Posted: Tue Nov 01, 2022 11:48 pm
by paulp575
In my main document I have places where I want the users to be able to jump to another web page.
When they are done on that page, I'd like them to click on a button and return to the same place they were at on the maim document.

Here's the code I use to send them from the main page to another web page:

Code: Select all

I've created a <a href="trains-modern-AFT.htm" target="_blank">separate web page</a> with all the details.
Once they are on that page, at the bottom I'm using the following code to have that page close and go back to the page they came from - hopefully in the exact place where they left the page. Here's that code:

Code: Select all

<a class="BTN MENU" href="javascript:history.go(-1)">Return to &quot;My Model Train Collection&quot; Main Page</a>
I've also tried this code, but still doesn't work:

Code: Select all

<a class="BTN MENU" javascript:history.back()">Return to &quot;My Model Train Collection&quot; Main Page</a>
I'm using Firefox version 106.0.2. Tried it on Microsoft Edge v106.0.1370.42 and Google Chrome v99.0.4844.51; doesn't work on any of them.

Maybe because I'm using target="_blank" is causing the problem?

Re: Click link; then go back

Posted: Wed Nov 02, 2022 12:36 am
by Albert Wiersch
paulp575 wrote: Tue Nov 01, 2022 11:48 pm Maybe because I'm using target="_blank" is causing the problem?
Yes, I think that is exactly right.

You are creating a new History object when you create a new tab by using target="_blank". And it seems that the new History object won't contain the original page that caused it to be created, so you won't be able to navigate back to it.

https://developer.mozilla.org/en-US/doc ... ow/history

Does the navigation work like you want it to when you don't use target="_blank"?

Re: Click link; then go back

Posted: Wed Nov 09, 2022 3:52 pm
by paulp575
Yes, by removing the target=_blank part it works as it should.

Thanks!