[SOLVED] Click link; then go back

For general web development questions that are not specifically related to CSS HTML Validator. This includes (but is not limited to) general HTML, CSS, Accessibility, JavaScript, and SEO questions.
Post Reply
paulp575
Rank IV - Intermediate
Posts: 170
Joined: Tue Aug 09, 2005 1:20 pm
Location: Spokane WA
Contact:

[SOLVED] Click link; then go back

Post 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?
Last edited by paulp575 on Wed Nov 09, 2022 3:53 pm, edited 1 time in total.
paulp575
User avatar
Albert Wiersch
Site Admin
Posts: 3783
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Click link; then go back

Post 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"?
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
paulp575
Rank IV - Intermediate
Posts: 170
Joined: Tue Aug 09, 2005 1:20 pm
Location: Spokane WA
Contact:

Re: Click link; then go back

Post by paulp575 »

Yes, by removing the target=_blank part it works as it should.

Thanks!
paulp575
Post Reply