Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打开新选项卡时,使用Javascript刷新当前打开的选项卡_Javascript_Jquery_Tabs - Fatal编程技术网

打开新选项卡时,使用Javascript刷新当前打开的选项卡

打开新选项卡时,使用Javascript刷新当前打开的选项卡,javascript,jquery,tabs,Javascript,Jquery,Tabs,当通过单击第一个选项卡中的链接打开新选项卡时,是否可以刷新当前打开的选项卡? 基本上,最终结果是这样的:第一个选项卡打开,单击页面上在第一个选项卡中打开的链接(使用鼠标中键或类似的方法,只是为了使其在第二个选项卡中打开),在第二个选项卡中打开单击的链接,然后自动刷新第一个选项卡。我希望我的解释可以理解。注意:我不是在设计自己的网站,我想用Greasemonkey为网站制作一个插件。是的,它是用document.body方法 声明您的窗口: w = window.open("yourUrl", "

当通过单击第一个选项卡中的链接打开新选项卡时,是否可以刷新当前打开的选项卡?
基本上,最终结果是这样的:第一个选项卡打开,单击页面上在第一个选项卡中打开的链接(使用鼠标中键或类似的方法,只是为了使其在第二个选项卡中打开),在第二个选项卡中打开单击的链接,然后自动刷新第一个选项卡。我希望我的解释可以理解。注意:我不是在设计自己的网站,我想用Greasemonkey为网站制作一个插件。

是的,它是用document.body方法

声明您的窗口:

w = window.open("yourUrl", "MYtest", "width=700, height=500");
在函数中,您可以使用document.body方法访问:

html = "I Append my new html";
$(w.document.body).html(html);

您需要这样的代码(内部是jquery代码):


标题
未更新
$(函数(){
$(“#myLink”)。在(“单击”上,函数(事件){
event.preventDefault();
打开(event.target.href,“_blank”);
$(“#toUpdate”).text(“转到谷歌”);
}).on(“鼠标向下”,函数(事件){
event.preventDefault();
if(event.which==2)
$(“#toUpdate”).text(“转到谷歌”);
});
});

编辑以添加Firefox支持

假设您的页面上有以下链接:

<a href="http://server.com/url-to-second-tab" target="_new">Link which opens new tab and refreshes current one</a>
请在所有浏览器中测试它,因为在某些浏览器中,它可能会以弹出窗口而不是新选项卡的形式打开链接

作为一个快速测试,在Chrome上使用F12开发者工具打开,并在控制台中编写:

window.open('https://google.com', '_blank');location.reload();

我想我解释得不够好。这应该更好地说明我的意思:好吧,如果你不明白你想要什么,对不起。请补充更多细节。也许是一部最好的电影。似乎是唯一有效的,非常感谢:)
$(document).ready(function(){
   $('body').on('click','a',function(e){
        e.preventDefault()
        // Open new tab - in old browsers, it opens a popup window
        window.open($(this).attr('href'), '_blank');
        // reload current page
        location.reload();
   })
})
window.open('https://google.com', '_blank');location.reload();