如何制作自己的iframe? [英] How to make an own iframe?

查看:189
本文介绍了如何制作自己的iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作iframe,我可以设置源代码,而不仅仅是src?是否可以在没有src的情况下创建一个?

How to make an iframe, where I can set the source code, not just the src? Is it possible to create one without the src?

推荐答案

演示

//get the iframe
var iFrame =  document.getElementById('iframe_id');

//this is your reference variable for the iframe body tag
var iFrameBody;

//get the body
if (iFrame.contentDocument ){// FF
    iFrameBody = iFrame.contentDocument.getElementsByTagName('body')[0];
}
else if ( iFrame.contentWindow ){ // IE
    iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
}
else {
    iFrameBody = iFrame.contentDocument.body
}

iFrameBody.innerHTML = "i should be in the iframe";​

参考:

  • https://stackoverflow.com/a/927023/575527
  • https://stackoverflow.com/a/4149924/575527

请注意这是绑定到同源政策

do note that this is bound to the "same-origin policy"

这篇关于如何制作自己的iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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