简体   繁体   English

无法获得 .click 在新标签页中打开

[英]Cant get .click to open in a new tab

I'm working on a javascript macro to open a specific link on a site in a new tab, but I'm not able to get the link to open in a new tab.我正在使用 javascript 宏在新选项卡中打开网站上的特定链接,但我无法获得在新选项卡中打开的链接。

Here's the code:这是代码:

document.onload = window.frames[0].document.getElementsByClassName('TextCell SA Link FW100 AL')[0].click()

I've tried using the window.open() function, but it doesn't seem to be working for me.我试过使用window.open()函数,但它似乎对我不起作用。 Here's how I wrote it我是这样写的

document.onload=window.open(window.frames[0].document.getElementsByClassName('TextCell SA Link FW100 AL')[0].click(),'_blank')

HTML: HTML:

<td class="TextCell SA Link FW100 AL" 
    onclick="(function(e) { e.preventDefault(); e.stopPropagation(); return autotask.siteNavigation.__openPage(new Autotask.PopupPage('ProjectDetail','\/projects\/views\/100\/prjView_100.asp',false,'objectID','2359',false,false,new Autotask.PopupSettings(550,null,950,null,false))); })(event)">
    P20190930.0003
</td>

Syntax of window.open iswindow.open语法是

var window = window.open(url, windowName, [windowFeatures]); var window = window.open(url, windowName, [windowFeatures]);

Here, as you are trying to grab the click event of the td, window.open wont work在这里,当您尝试获取 td 的点击事件时, window.open不起作用

Try this.尝试这个。

// document.addEventListener('load', (event) =>
document.onload = (event) => {
  // var tdList = window.frames[0].document.getElementsByClassName('TextCell SA Link FW100 AL');
  var tdList = window.frames[0].document.querySelectorAll('.TextCell.SA.Link.FW100.AL');
  if(tdList && tdList.length) {
    tdList[0].click();
  } else {
    alert('TD not found.');
  }
};

Please note that it请注意它

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

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