简体   繁体   English

href 目标 _blank 无法正常工作 - 未在新选项卡中打开链接,javascript 以不同方式处理事件

[英]href target _blank not working properly - not opening link in new tab , javascript handling the event diferently

I'm having a problem with a href target _blank on my website.我的网站上的 href 目标 _blank 有问题。

I cannot determine why it is not opening the link in a new tab, https://miwebstudio.com in the section: LATEST PROJECTS > Boranito skat and others, in fact, is instead opening the link in the same tab... can someone explore my website and tell me what is happening and how to solve it?我无法确定为什么它没有在新选项卡中打开链接, https://miwebstudio.com部分:最新项目> Boranito skat 和其他人实际上是在同一个选项卡中打开链接......可以有人浏览我的网站并告诉我发生了什么以及如何解决它? I think it does have to be something with the JS but I am not able to find the problem in the Javascript code since I am a javascript rookie and cannot understand properly what the javascript code here does...我认为它确实与 JS 有关,但我无法在 Javascript 代码中找到问题,因为我是 javascript 菜鸟,无法正确理解 javascript 代码的作用......

from what I have understood due to previous google and StackOverflow research and behavior watching, it is because javascript is handling the event target _blank in a different way, in fact, javascript here is being used for website change( i mean every click you do on the menu, some divs appears, some divs disappears and it is being handled by 3 js classes), already examined the JS files, clicked right-click, used element inspector> elements> event listeners>click event to see which JS files are being triggered while clicking...根据我之前的 google 和 StackOverflow 研究和行为观察的理解,这是因为 javascript 以不同的方式处理事件目标 _blank,实际上,这里的 javascript 被用于网站更改(我的意思是您在菜单,一些 div 出现,一些 div 消失,它正在由 3 个 js 类处理),已经检查了 JS 文件,单击右键,使用元素检查器>元素>事件侦听器>单击事件以查看正在处理的 JS 文件点击时触发...

see here detailed image看这里详细图片

as you can see, two javascript archives are executing while doing the click event:如您所见,在执行单击事件时正在执行两个 javascript 存档:

1: `jquery.pagepiling.min.js. //// 2: animsition.js`

3: scripts.js

so apparently both javascript classes are handling the events: on click, but since I am a newbie in javascript I cannot understand how to handle this or even understand what the JS does to the website ( i am just tinkering with the given template to try to understand it and to customize it better, (and hence, make the target _blank work properly( as exposed before, while clicking the link, it opens the link in the same page) so I come here for some support of you所以显然两个 javascript 类都在处理事件:点击时,但由于我是 javascript 的新手,我无法理解如何处理这个问题,甚至无法理解 JS 对网站的作用(我只是在修改给定的模板以尝试理解它并更好地定制它,(因此,使目标 _blank 正常工作(如前所述,单击链接时,它会在同一页面中打开链接)所以我来这里是为了给你一些支持

Here is the code snippet for you to be able to locate easily inside my website the code while using the code explorer in chrome:这是代码片段,您可以在使用 chrome 中的代码资源管理器时轻松地在我的网站中找到代码:

<a href="project-detail.html" target="_blank" class="project-box">
<div class="project-box-inner">
<h5>Boranito<br>Skat</h5>
<div class="project-category">House Design</div>
</div>
</a>

however, will leave the javascript source files here since I am requested to give all possible details here to avoid users being in the need of accessing my website my website , here are all the 3 javascript classes handling all the template events which I don't know what they do: (since I am not able to attach the source code of the javascript classes, I will attach a link for each js file so you could check it, thanks in forward.....但是,将在此处留下 javascript 源文件,因为我被要求在此处提供所有可能的详细信息以避免用户需要访问我的网站我的网站,这里是处理所有模板事件的所有 3 个 javascript 类我不知道他们在做什么:(由于我无法附上 javascript 类的源代码,我会附上每个 js 文件的链接,以便您查看,谢谢转发.....

1: animsition.js 1:动画.js

2: 2:

jquery.pagepiling.min.js jquery.pagepiling.min.js

3: 3:

scripts.js脚本.js

Thank you in advance.先感谢您。

Problem问题

Your script (scripts.js) on line 13 toggle animsition's feature for links: linkElement: "a.project-box" .您在第 13 行的脚本 (scripts.js) 切换 animsition 的链接功能: linkElement: "a.project-box" This will add an handler to every a element with a project-box class.这将为每个带有project-box class a元素添加一个处理程序。 The handler is the following code (I've commented for your understanding):处理程序是以下代码(我已评论以供您理解):

function(event) {
  event.preventDefault(); // prevent the default behavior for links (prevent the behavior you want)
  var $self = $(this);
  var url = $self.attr('href'); // get the url of the link
  if (event.which === 2 || event.metaKey || event.shiftKey || navigator.platform.toUpperCase().indexOf('WIN') !== -1 && event.ctrlKey) {
    // open the link in a new tab ONLY IF I clicked on it with the middle mouse button or with Ctrl/Cmd pressed
    window.open(url, '_blank');
  } else {
    // Else do the animation and open the link in the same tab
    __.out.call(_this, $self, url);
  }
}

Fix使固定

To fix your problem, you can either要解决您的问题,您可以

  • Change the way you setup Animsition, be aware that it can modify other links/behaviors in your site更改设置 Animsition 的方式,注意它可以修改您网站中的其他链接/行为
  • Change the class of your link so it is not matched as the linkElement of your Animsition's setup.更改链接的linkElement使其与 Animsition 设置的链接元素不匹配。 For example: remove the class of the a element (it will affect the styling) and you will see that the link opens in a new tab.例如:删除a元素的 class (它会影响样式),您将看到链接在新选项卡中打开。

Appendix附录

You can find the handler's code in the devtools -> your link element -> handlers -> click.您可以在 devtools -> your link element -> handlers -> click 中找到处理程序的代码。 开发工具截图

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM