如何用内容脚本中的popup.html注入iframe [英] how to inject iframe with popup.html from content script

查看:270
本文介绍了如何用内容脚本中的popup.html注入iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将popup.html注入到网页内容中。以下是我的想法

I want to inject popup.html to web content. Below is my think

... page content

<div> <--! injected content !-->
   <iframe src="chrome-extension:/21jk32j11k3kj11/popup.html">
   </iframe>
</div>

是否可以在web内容中显示popup.html?

Is it possible to show popup.html in web content?

推荐答案

这是可能的。当清单版本 2处于活动状态(Chrome 18中引入,需要在Chrome 23中使用) ,您必须将该页面包含在 web_accessible_resources部分的清单文件

That's possible. When manifest version 2 is active (introduced in Chrome 18, required in Chrome 23), you have to include the page in the "web_accessible_resources" section of the manifest file though:

{ ...
    "web_accessible_resources": ["popup.html"],
  ...
}

框架本身可以通过内容脚本注入,请参阅用法和示例:

The frame itself can be injected via a Content script, see the documentation for usage and examples:

// Within a content script:
var f = document.createElement('iframe');
f.src = chrome.extension.getURL('popup.html');
document.body.appendChild(f); // Append to body, for example.

chrome.extension.getURL 返回绝对URL popup.html ,例如 chrome-extension://...32 letters ... / popup.html

这篇关于如何用内容脚本中的popup.html注入iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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