Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jquery - HTML/Javascript - Navigate to an already opened browser tab/window

I have an application that has a dashboard page. Different links on the dashboard page open as different browser tabs or windows based on the user's browser setting. Each new page/tab opened has a "Go back" button in the header. The application uses bootstrap framework for layout.

What I'm after is, on the new page, when a user clicks on the "Go back" button", I'd like the user to be taken back to the dashboard page/tab. (Please note, I'm not after loading the dashboard page on the current page.

Is this achievable? If yes, can I please request an example?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As you may have guessed from the comments, you can't do this (certainly not in any standardised, accepted and future proof way), and it's a good thing too as this could (and has been) abused in the past by advertisers and is generally bad practice.

As a general rule you shouldn't be hijacking the users expected behaviour of clicking on a link by opening it a new window/tab anyway. If the user wants it in a new tab, they can just right click the link and 'Open in New Tab'. It's only in rare cases that you should be forcing things to open in a new window.

Remember that when you force something to open in new window you are also breaking the expected behaviour of the back button. When someone clicks one of your links but suddenly realises they didn't want to be there, what's the first thing they'll do, hit the back button. But now it doesn't go back, they have to either click a link you've put in somewhere or close the new window, which they may not have noticed opening to begin with. Don't underestimate the usefulness of the back button, it's the users ejector seat. Break it at your peril.

In the example you gave us here

Different links on the dashboard page open as different browser tabs or windows

I have just one question. Why? Do you have a very valid reason that the dashboard page can't be navigated away from? You've said you're putting in a 'go back' button, and the users back button will do that as well, so it's not like they're never going to get back to the page. Maybe the user has customised their dashboard in some way? In which case maybe considering saving their state using something along the lines of localstorage or cookies.

There could be any number of reasons you are wanting to achieve this, and they could be valid, but since you really can't maybe it's a good time to rethink some of your assumptions about how the UI should work. You could get help with UI questions over at http://ux.stackexchange.com


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...