简体   繁体   English

在Chrome扩展程序中将远程URL显示为弹出窗口

[英]Show a remote URL as popup in a chrome extension

I am developing a Chrome addon and I need to show a remote URL as a popup. 我正在开发一个Chrome插件,我需要显示一个远程URL作为弹出窗口。 I have tried the following in manifest.json . 我已经在manifest.json尝试了以下内容。

"browser_action": {
    "default_title" : "Pennyful",
    "default_popup" : "http://www.google.com"
}

This was not working. 这不起作用。 So I handled the event and set the popup from code. 因此,我处理了该事件并从代码中设置了弹出窗口。

chrome.browserAction.onClicked.addListener(function() {
    chrome.browserAction.setPopup({popup: "http://www.google.com"});
});

This also didn't work. 这也没有用。 I have also tried creating a html page packaged with the addon, and when loaded does a JS redirect to the remote website. 我也尝试过创建一个与插件打包在一起的html页面,并且在加载时会执行JS重定向到远程网站。 This didn't work. 这没用。 Then I put a iframe inside the page and set the remote URL as source to the iframe . 然后,我将iframe放入页面中,并将远程URL设置为iframe源。 In this case iframe shows up, but it takes long time to load the page and the width is incorrect. 在这种情况下,会显示iframe,但加载页面需要花费很长时间,并且宽度不正确。

So it looks like there is no way to set a remote URL as a popup page. 因此,似乎无法将远程URL设置为弹出页面。 I'm wondering is there any way to achieve this? 我想知道有什么方法可以实现这一目标吗?

In short, no , you can't just open an external website without using an iframe into your popup.html file. 简而言之, ,您不能不使用iframe进入popup.html文件就直接打开外部网站。

This Google Developer Codelabs article goes through how to use external service APIs (like Twitter or Flickr) to display information from another site in your popup. Google Developer Codelabs文章介绍了如何使用外部服务API(例如Twitter或Flickr)在弹出窗口中显示来自另一个站点的信息。 That might be the way to go if an iframe doesn't work for what you're trying to do. 如果iframe无法实现您要尝试的操作,那可能就是解决方法。

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

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