[英]contentScript: self.on('click', function() { tabs.open(url) }) - I can't open new tab here
[英]JS click function open url in new windown
我使用html创建带有文本的链接,我想在用户单击它时转到特定的URL。 我是javascript新手!
这是我的代码
<a class="dt-button add_new_table_entry DTTT_button DTTT_button_new" tabindex="0" aria-controls="table_1" href="#">
<span>Add new</span>
</a>
我的剧本
$("dt-button add_new_table_entry DTTT_button DTTT_button_new").click(function () {
window.location="http://project.co/add-new/";
});
更新我已经创建了我的脚本
let classic = document.getElementsByClassName('add_new DTTT_button DTTT_button_new');
for (var i=0; i < classic.length; i++) {
classic[i].addEventListener("click", clickfunc, false);
}
function.clickfunc(){
document.location.href="http://google.com";
}
但是给错误意外令牌;
javascript打开新窗口
window.open(url, windowName, "height=200,width=200");
您没有任何名为add_new
类。 在getElementsByClassName
参数中使用单个唯一的类就足够了。 请尝试以下操作:
let classic = document.getElementsByClassName('dt-button');
for (var i=0; i < classic.length; i++) {
classic[i].addEventListener("click", clickfunc, false);
}
function clickfunc(){
window.open("http://google.com","_blank");
}
使用以下代码
$("dt-button add_new_table_entry DTTT_button
DTTT_button_new").click(function () {
window.open("http://project.co/add-new/");
});
创建一个函数:
function openlink()
{
window.open("http://project.co/add-new/","mywindow","menubar=no,resizable=1,width=400,height=400");
}
然后使用以下命令调用该函数:
<a href="javascript:openlink();">Link Text</a>
尝试一下,它将起作用,在单击class = add_new_table_entry时,将调用javascript click事件,并且在同一窗口重定向中,我们使用window.location进行重定向
添新
$(".add_new_table_entry").click(function () {
window.location ="http://project.co/add-new/";
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.