简体   繁体   English

href链接仅在“右键单击新标签”中打开

[英]href links only open on “right click in new tab”

I'm having trouble with some script interfering with my basic href links and not allowing them to open on left click. 我遇到了一些脚本干扰我的基本href链接,并且不允许它们在单击鼠标左键时打开的麻烦。

My url is http://www.mayabdesign.com , and on each specific project page (like http://www.mayabdesign.com/#cbp=ajax/sculptjax.html ) the "view the site" button does nothing unless you right click and open in a new tab. 我的网址是http://www.mayabdesign.com ,并且在每个特定的项目页面(例如http://www.mayabdesign.com/#cbp=ajax/sculptjax.html )上,“查看站点”按钮都没有作用,除非您右键单击并在新选项卡中打开。 I know the problem, but can't seem to figure out the solution. 我知道问题所在,但似乎无法找出解决方案。

Thanks in advance. 提前致谢。 :) :)

Add click function to Dom Ready 将点击功能添加到Dom Ready

$(document).ready(function(){
    $("a").click(function( event ) {
          if ( $(this).attr("href").match("#") ) {
          event.preventDefault();
          var href = $(this).attr('href').replace('#', '')
          scrollToAnchor( href );
    });
});

CHECK DEMO HERE 在此处检查演示

我认为点击事件被event.preventDefault()阻止了

This is the relevent code that is preventing the link from returning. 这是阻止链接返回的相关代码。 Since the href value does in fact math # its default action is prevented 由于href值实际上是数学#它的默认操作被阻止

$("a").click(function( event ) {
      if ( $(this).attr("href").match("#") ) {
      event.preventDefault();
      var href = $(this).attr('href').replace('#', '')
      scrollToAnchor( href );
});

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

相关问题 右键单击启用“在新标签页/窗口中打开” - Enable “open in new tab/window” in right click 右键单击并保存链接以在新选项卡中打开 - Right Click and save link to open in new tab 鼠标中键单击链接以仅打开新选项卡ASP C# - Middle Mouse Click on Links To Open New Tab Only ASP C# 链接未打开,除非我右键单击新标签 - Links not opening, except when I right click new tab 语法错误: <a>链接无法通过单击操作,只能通过右键单击+“在新选项卡中打开链接”命令打开</a> - Syntax error: <a> link not working by clicking, only opens by right click + “open link in new tab” command emberjs所需的页面不会在“右键单击在新选项卡中打开”上打开 - emberjs desired page wont open on “right click open in new tab” href =“ javascript:”在新标签页中打开 - href=“javascript:” open in new tab 当我右键单击选定的选项卡并在新选项卡上打开它时,它总是打开默认的活动选项卡 - when i right click on selected tab and open it on new tab ,it always open the default active tab 鼠标右键单击并在新选项卡中打开在angularjs中不起作用 - Mouse right click and open in new tab does not work in angularjs 打开禁用了右键单击选项的新窗口/选项卡(JavaScript) - Open new window/tab in which right click option is disabled (JavaScript)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM