简体   繁体   English

运行 javascript 的链接打开另一个页面。 如果用户使用中键单击或右键单击菜单,如何在新选项卡中执行此操作

[英]link running a javascript that open another page. how to make it do it in new tab if user uses middle click or right click menu

I have this link in my left navigation: dashboard我的左侧导航中有此链接:仪表板

That javascript opens a link based on the passed parameters. javascript 根据传递的参数打开一个链接。

All works fine, but I would like to be able to use the browser capabilities of opening the links in a tab (when user is using middle click or selects 'Open link in new tag' from right click menu).一切正常,但我希望能够使用浏览器功能在选项卡中打开链接(当用户使用中键单击或从右键菜单中选择“在新标签中打开链接”时)。 Though, this is not working for links handled with javascript code.但是,这不适用于使用 javascript 代码处理的链接。

There are many reasons why this is not the default behaviour of the browser (eg javascript function might only do some validation and stay in the page... browser can't know what the js might do or if a new window/dialog will result from that action so would make no sense to open new tag as a result of a middle click...).这不是浏览器的默认行为有很多原因(例如 javascript function 可能只进行一些验证并留在页面中......浏览器无法知道 js 可能会做什么或是否会导致新窗口/对话框从该操作开始,由于中键单击而打开新标签是没有意义的......)。 But hopefully there is a workaround for the default behaviour.但希望有默认行为的解决方法。

Any idea how this could be done?知道如何做到这一点吗?

Cheers, Stef.干杯,史蒂夫。

Javascript links execute in context of the page where they are called. Javascript 链接在调用它们的页面的上下文中执行。 If you "open" the link in a new tab/window, the javascript code will be executed in the new window, ie, empty, and will most probably fail.如果您在新选项卡/窗口中“打开”链接,javascript 代码将在新的 window 中执行,即为空,并且很可能会失败。

A browser could try to add the feature you are asking for by cloning the page which contains the link, and executing the javascript code in the context of the cloned page.浏览器可以通过克隆包含链接的页面并在克隆页面的上下文中执行 javascript 代码来尝试添加您要求的功能。 But this would most likely break some critical sites (imagine for example that your online banking site works with javascript, so when you open a link in a new tab/window, cloning the original window might lead to a duplicate transaction).但这很可能会破坏一些关键站点(例如,假设您的网上银行站点使用 javascript,因此当您在新选项卡/窗口中打开链接时,克隆原始 window 可能会导致重复交易)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使鼠标“中键”不在页面上的新选项卡中打开? - How to make mouse "Middle Click" not to open in new tab on a page? 即使用户单击“中间按钮”或右键单击->在新选项卡中打开,如何触发jquery“单击”事件 - How to trigger jquery “click” event even when the user clicked “middle button” or right click -> open in a new tab 当链接具有javascript时,在IE中禁用了右键菜单上的在新标签页中打开 - Open in new tab on right click menu was disable in IE while link has javascript 如何使用 javascript 在新标签页中打开网页并单击鼠标中键 - How can I open webpage in new tab with javascript and middle click 右键单击并保存链接以在新选项卡中打开 - Right Click and save link to open in new tab 点击链接并调用javascript,然后点击“在新标签页中打开” - Click link and call javascript and then “Open in new tab” 单击另一个页面上的链接时如何单击相应的选项卡? - How to make a click on the corresponding tab when clicking a link on another page? 通过 JavaScript 在新选项卡中单击中键打开 url - Open url in new tab with middle click via JavaScript emberjs所需的页面不会在“右键单击在新选项卡中打开”上打开 - emberjs desired page wont open on “right click open in new tab” 右键单击 Ant Design 的折叠菜单项不显示“在新选项卡中打开” - Right click on Collapsed Menu Item of Ant Design do not show "Open in new tab"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM