HTML/Javascript - 导航到已打开的浏览器选项卡/窗口 [英] HTML/Javascript - Navigate to an already opened browser tab/window

查看:22
本文介绍了HTML/Javascript - 导航到已打开的浏览器选项卡/窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有仪表板页面的应用程序.仪表盘页面上的不同链接根据用户的浏览器设置作为不同的浏览器选项卡或窗口打开.每个打开的新页面/标签页的标题中都有一个返回"按钮.该应用程序使用引导框架进行布局.

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?

推荐答案

正如您可能从评论中猜到的那样,您不能这样做(当然不是以任何标准化、接受和面向未来的方式),这是一个很好的也因为这在过去可能(并且已经)被广告商滥用,并且通常是不好的做法.

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.

在你给我们的例子中

仪表盘页面上的不同链接作为不同的浏览器选项卡打开或窗户

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

我只有一个问题.为什么?您是否有一个非常正当的理由无法导航仪表板页面?您已经说过要放置一个返回"按钮,用户的后退按钮也会这样做,因此他们并不是永远不会返回该页面.也许用户以某种方式自定义了他们的仪表板?在这种情况下,可以考虑使用类似 localstorage 或 cookie 的东西来保存他们的状态.

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.

您想要实现这一目标的原因可能有多种,它们可能是有效的,但由于您确实不能这样做,也许现在是重新考虑您对 UI 应该如何工作的一些假设的好时机.您可以在 http://ux.stackexchange.com

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

这篇关于HTML/Javascript - 导航到已打开的浏览器选项卡/窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆