简体   繁体   English

右键单击超链接/操作链接/链接按钮时,未出现“在新选项卡或页面中打开”

[英]'Open in New Tab or Page' not appearing when Hyperlink/Action Link/Link Buttons are right-clicked

I'm trying to call a JavaScript function from an ASP.NET MVC view (.html) using Action Link/Hyperlink()/Link Buttons. 我正在尝试使用Action Link / Hyperlink()/ Link Buttons从ASP.NET MVC视图(.html)调用JavaScript函数。 Left click works good, but right clicking the link and choosing 'Open a New Tab or Page' is not working. 左键单击效果很好,但是右键单击链接并选择“打开新标签页或页面”无效。

My attempt so far has been: 到目前为止,我的尝试是:

<a href="#" onclick=aFunction()>link</a>

    aFunction(object)
    {
       alert('Inside Javascript Function')
    }

This answer might help. 这个答案可能会有所帮助。

Try giving your hyperlink an id attribute (say, id="foo" ), and create a click handler that performs a specified action whenever a#foo is right-clicked: 尝试给您的超链接提供id属性(例如id="foo" ),并创建一个单击处理程序,该处理程序将在右键单击a#foo时执行指定的操作:

document.getElementById("foo").onmousedown = function(event) {
    if (event.which == 3) {
        alert('Inside Javascript Function');
    }
}

EDIT : 编辑

Per your comment: 根据您的评论:

I don't want to execute the function as soon as the user right click. 我不想在用户右键单击后立即执行该功能。 I want execute the function after the user right click the link and click open new tab option. 我想在用户右键单击链接并单击“打开新选项卡”选项后执行该功能。

I don't believe this is possible (unless there is some arcane Chrome JavaScript API that detects such an event). 我认为这是不可能的(除非有一些不可思议的Chrome JavaScript API可以检测到此类事件)。 It wouldn't make sense for JavaScript to know how Chrome works. 对于JavaScript而言,了解Chrome的工作原理毫无意义。 Further, JavaScript is sandboxed in such a way that it doesn't have access to the user's local file system - by extension, it should not know what the Google Chrome process itself is doing. 此外,对JavaScript进行沙箱处理的方式是,它无法访问用户的本地文件系统-扩展来说,它不应该知道Google Chrome进程本身在做什么。

Use the approach mentioned in this answer: How to run function on new tab from main tab? 使用此答案中提到的方法: 如何在主选项卡的新选项卡上运行功能? (Google Chrome) (谷歌浏览器)

Basically you would store the function in local storage and on page load event of the page this links open, you would check if there is a function stored in the local storage, and if so, then execute it. 基本上,您会将功能存储在本地存储中,并且在此链接打开的页面的页面加载事件中,您将检查本地存储中是否存储有功能,如果有,则执行该功能。

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

相关问题 Javascript超链接(.link)在新选项卡中打开 - Javascript hyperlink(.link) open in new tab 如何在单击链接时打开新选项卡或窗口? - How can I open a new tab or window when a link is clicked? 从其他页面单击链接时打开特定选项卡 - Open specific Tab when link is clicked from another page 如何打开在新标签页中点击的链接? - How to open the link clicked in a new tab? 链接(带有重定向)将以隐身方式打开,或在新标签页中打开,或者显式声明新页面。 只是单击不起作用 - Link (with redirects) opens in incognito or when open in new tab, or new page is explicitly declared. Doesn't work when just clicked 当单击某个网页上的某个位置时,打开一个新页面(例如链接) - When clicked somewhere on a certain webpage, open a new page(like a link) 单击链接后,打开带有URL的选项卡 - Open a tab with a URL when link clicked 右键单击并保存链接以在新选项卡中打开 - Right Click and save link to open in new tab 右键单击网站上的链接时,缺少“在新标签页中打开链接”选项 - 'open link in new tab' option missing when right clicking a link on website 单击带有滚轮的链接会在新选项卡中打开,但在执行右键单击+打开新选项卡时不会打开 - clicking on a link with scroll wheel opens in a new tab but not when right-click + open new tab is performed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM