Chrome扩展程序:如何在同一标签中的popup.html中打开网址 [英] Chrome Extension: How do i open urls in popup.html in the same tab

查看:499
本文介绍了Chrome扩展程序:如何在同一标签中的popup.html中打开网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌浏览器扩展程序:



我对一件简单的事情很生气。请不要责怪我,我不是英文原籍,我无法阅读和理解所有的扩展文档。



我只是想做以下事情:



我可以在我的popop.html中说8个不同的网址,当我点击右上角的浏览栏中的图标时,它会打开。

(url)example.com

(url)其他例子等...



点击一个网址什么也不做, target =_ blank总是会打开一个新选项卡,但是我想在点击一个选项卡时在同一个选项卡中打开它们。 target =_ top target =_ self在这里似乎不起作用。

我不知道如何编程。我来自PHP而我需要一个快速解决方案。

有没有人愿意(容易理解)代码片段或想法如何在同一个标​​签中打开我的网址? (在哪里放置什么)
(到目前为止我明白了清单的定义,但是对于我来说,所有这些java上下文对于我来说目前太难理解了,只能用于这个简单任务)。 b
$ b

预先感谢
RJ

解决方案

我相信chrome不允许弹出窗口以任何方式打开外部页面。我知道的唯一解决方案是在 popup.html 文件中放置一个 iframe ,其中 src 属性设置为 popup2.html ,并将所有html放置在 popup2.html 中。但是,请考虑所有网站在iframe内不能正常工作。



如果您尝试在当前活动选项卡中打开网址,请尝试以下操作:



将以下脚本附加到您的popup.html文件中:

  var hrefs = document.getElementsByTagName(a); 

函数openLink(){
var href = this.href;
chrome.tabs.query({active:true,currentWindow:true},function(tabs){
var tab = tabs [0];
chrome.tabs.update(tab.id ,{url:href});
});
}

for(var i = 0,a; a = hrefs [i]; ++ i){
hrefs [i] .addEventListener('click',openLink );

$ / code>

您需要添加标签 permisson到你的清单文件以便使用。


Google Chrome extension:

i am running mad on a simple thing. Please dont blame me, i am not english origin and i have trouble to read and understand all the extension docs.

I simply want to do the following:

I have lets say 8 different URLs in my popop.html which opens when i click on my icon in the top right browserbar.
(url) example.com
(url) Other Example and etc ...

clicking an url does nothing, target="_blank" opens always a new tab but i want to open them all in the same tab when clicking on one. target="_top" or target="_self" doesnt seem work here.

I have no idea how to program this. I come rather from php and i need a quick solution.

Has anyone a litte ready (easy to understand) code snippet or an Idea how to open my urls in the same tab ? (where to place what) ( i understood the manifest definitions so far, but all this java up and down is too difficult to understand for me at the moment only for this "simple" task).

Thanks in Advance RJ

解决方案

I believe that chrome does not allow the popups to open an external page by any way. The only solution I know is to place an iframe in your popup.html file with src attribute set to popup2.html and place all your html inside popup2.html. However, consider that all websites do not work well inside iframe.

If you are trying to open url in currently active tab then try following:

Attach following script to your popup.html file:

var hrefs = document.getElementsByTagName("a");

function openLink() {
    var href = this.href;
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        var tab = tabs[0];
        chrome.tabs.update(tab.id, {url: href});
    });
}

for (var i=0,a; a=hrefs[i]; ++i) {
    hrefs[i].addEventListener('click', openLink);
}

You need to add tabs permisson to your manifest file for this to work.

这篇关于Chrome扩展程序:如何在同一标签中的popup.html中打开网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆