【发布时间】:2011-11-22 12:10:17
【问题描述】:
所以我通过将内容脚本注入正文来创建这个 chrome 扩展:
这是我的javascript:
test.js:
$(document).ready(function(){
Url = chrome.extension.getURL('etc.html');
link = '<iframe src="' + Url + '" id="frame" scrolling="no" frameborder="0px"></iframe>';
$('body').prepend(link);
alert($('.test').html());
});
这是 etc.html 的内容,应该放到 iframe 中
等.html:
<div class="test">An html</div>
这是我的 manifest.json
manifest.json:
{
"content_scripts": [ {
"all_frames": true,
"js": [ "js/jquery.js", "js/test.js" ],
"matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_end"
} ],
"description": "Testing",
"name": "test",
"permissions": [ "tabs", "http://*/*", "https://*/*", "notifications", "management", "unlimitedStorage", "bookmarks", "contextMenus", "cookies", "geolocation", "history", "idle" ],
"version": "2.0.0.53"
}
iframe成功插入body,出现iframe内容,通过chrome inspector看到...
但是当 js 运行 alert($('.test').html()); 行时,它返回 null 而不是返回 html....在开发此类扩展时,我究竟如何访问 iframe 中的内容
我也试过$('#frame').contents().find('.test').html();,但无济于事
【问题讨论】:
标签: javascript jquery google-chrome iframe google-chrome-extension