【发布时间】:2016-07-13 01:42:53
【问题描述】:
无论出于何种原因,这并不重要,我正在尝试通过 iframe 将谷歌购物与另一个页面结合起来。
我尝试了here 提出的方法,包括在 iframe 中嵌入谷歌自定义搜索查询,但谷歌自定义搜索不允许访问购物标签。
我想,如果您无法嵌入 Google,请将自己嵌入其中。所以我继续在页面中注入一些 jQuery
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
将google购物搜索结果页面清理为我需要的内容,即div#search中的html
jQuery(function($) {$('#search').show().parentsUntil('body').andSelf().siblings().hide();});
创建一个 iframe 并注入它:
var iframe = document.createElement('iframe')
iframe.src="http://example.com"
iframe.width="100%";
iframe.height="500";
iframe.style="visibility:visible";
document.body.appendChild(iframe)
唯一的问题是 iframe 不加载页面的内容,因此是空白的。如果您在任何其他页面中尝试上述 sn-p,它就会起作用。谷歌似乎阻止加载 iframe。我怎样才能解决这个问题?
【问题讨论】:
-
Google 搜索结果无法在 IFrame 中使用。
标签: javascript jquery html css iframe