Chrome 扩展程序可以访问 iframes 吗? [英] Do Chrome extensions access iframes?

查看:28
本文介绍了Chrome 扩展程序可以访问 iframes 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我编写了一个在页面上运行一段 JS 代码的 Chrome 扩展程序,它是否也会在我创建的任何 iframe 中运行?如果是这样,这是否适用于 DOM 加载后由 Javascript 创建的 iframe?

if I write a Chrome extension that runs a snippet of JS on a page, will it also run in any iframes I create? If so, does this apply for iframes created by Javascript after the DOM has loaded?

谢谢!

推荐答案

是的,Chrome 扩展内容脚本"可以在所有 iframe 中运行(页面加载时最初位于 HTML 中).为了让内容脚本在所有框架中运行,您需要在 Chrome 扩展 manifest.json 中使用 all_frames 属性对其进行配置:

Yes, a Chrome Extension "content script" can run in all iframes (that are initially in the HTML when the page is loaded). In order to have the content script run in all frames you need to configure it to do so in the Chrome Extension manifest.json using the all_frames property:

http://code.google.com/chrome/extensions/content_scripts.html>

{
  "name": "My extension",
  ...
  "content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "css": ["mystyles.css"],
      "js": ["jquery.js", "myscript.js"],
      "all_frames": true
    }
  ],
  ...
}

不,内容脚本不会在页面中通过 JavaScript 动态加载的 iframe 中执行.

No, the content scripts will NOT execute in the iframes loaded dynamically via JavaScript in the page.

这篇关于Chrome 扩展程序可以访问 iframes 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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