繁体   English   中英

在Google Chrome扩展程序上打开外部网站

[英]Open an external website on Google Chrome Extension

所以,我正在尝试使用谷歌Chrome扩展程序。

我已经完成了50%的脚本,但是我停了一步:

如何加载外部网站 - 例如:www.mysite.com/page.php-在popup.html?

我使用iFrame时只取得了成功,但是,这是丑陋和不安全...... :(

有没有办法用jquery(ajax)来做?

提前致谢。


所以,这就是我的manifest.json:

{
  "manifest_version": 2,

  "name": "XCLickF",
  "description": "X file",
  "version": "1.0",
  "background": { "scripts": ["jquery-1.9.1.min.js","background.js"] },

  "permissions": [
        "http://*/*",
        "https://*/*"
    ],
  "browser_action": {
    "default_icon": "icon.png",
"default_title": "XMail",
    "default_popup": "popup.html"
  }
}

我的background.js是怎样的:

function poll() {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = handleStateChange; // Implemented elsewhere.
    xhr.open("GET", 'http://disqus.com/', false);
    xhr.send(null);
    console.log(xhr.responseText);
}

function handleStateChange() {
    if (this.readyState == 4) {
        var resp = JSON.parse(this.responseText);
        updateUi(resp);
    }
}

function updateUi(json) {
    console.log("JSON: ", json);
}

实际上你可以使用jquery ajax(或xhr)获取该页面的所有html。 获得html后,你必须设置/执行js'。 此外,您还可以重定向到您的网页(但主要是它可以从谷歌商店禁止)您不能使用iframe显示页面。

$.ajax({
  url: 'www.google.com',
  success: function(data) {
    console.log(data); // data gives all of html
  }
});

您也可以跨域免费iframe插件,这可能有助于您的工作。

Iframe Height Jquery插件

Iframe Resizer

暂无
暂无

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

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