【发布时间】:2013-09-29 17:55:35
【问题描述】:
大道!
亲爱的人们..
我想扩展我的“Google 自定义搜索代码”
在 Extension Popup (popup.html) 中显示我网站的搜索结果
我在使用它进行扩展时遇到问题。
当我从本地计算机加载 iframe 时弹出窗口显示文本但未显示搜索对话框。
当我从 GoogleDrive 加载 iframe 时,iframe 正在显示,但加载需要将近 3 4 秒。
-------(第3号我解决成功) 链接没有在新标签中打开我太累了请帮我在新标签中打开链接? (在 Google Search API 中有一个选项 Search Features> Advance > Target Link ...我把值 _Blank)
非常感谢!
代码如下。
manifest.json
{
"name": "Instant Search!",
"description": "Search My Blog Instantly!",
"version": "0.1",
"manifest_version": 2,
"browser_action": {
"default_popup": "popup.html",
"default_title": "Search My Blog"
}
}
Popup.html
<html>
<head>
</head>
<body>
<iframe width="400" height="400"
seamless="seamless"src="/QS.html"></iframe>
</body>
</html>
iframe 页面
<!DOCTYPE html>
<html>
<head>
<style>
.cse input.gsc-input, input.gsc-input {
background-image:url('/blank.gif')!important;
}
</style>
</head>
<body>
<script>
(function() {
var cx = '009043611225946488903:ntz9nyqubzw';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
</body>
</html>
【问题讨论】:
-
两个可能的问题:1) iframe 中的内联脚本(将其移动到单独的
foo.js并包含在<script src="foo.js">中,以及 2)包括通过 HTTP 而不是 HTTPS 的脚本,我think 被 Chrome 的默认 CSP 所禁止(因此将条件更改为默认使用 HTTPS——chrome-extension:的协议会触发 HTTP 加载)。
标签: javascript json html iframe google-chrome-extension