从访问跨源帧访问iFrame内容

时间:2015-05-19 06:12:04

标签: javascript jquery html iframe

我已经通过编码创建了iframe,只是将其附加到当前程序,在该行之后我尝试访问并从iFrame中的标头中删除标记。但是它说“DOMException:无法从'HTMLIFrameElement'中读取'contentDocument'属性:阻止了一个具有原点”null“的帧来访问跨源帧”。为什么会这样?如果它是不同的域然后确定,但这是创建并从相同的页面和程序追加。任何可能在iframe内设置权限以允许从外部访问。

我正在尝试下面的代码

var all_code="<style>.cs{color:red;}"<\/style>;
var iframe = document.createElement('iframe');
iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(all_code);
$(".blg_gen_container").css("width",glb_container_width+"px");
$(".blg_gen_container").css("height",glb_container_height+"px");

iframe.height=glb_widget_width+"px";
iframe.height=glb_widget_height+"px";
iframe.id="iframe_rdpostid";
$("#prev_code").empty();
$("#prev_code").append(iframe);

iBody = $('iframe:first').contents().find('body').clone();

0 个答案:

没有答案