使用jQuery从原始页面内容创建iframe
Create iframes from original page content with jQuery
我正在尝试将整个页面动态地"重写"为一组iframe。我想要在iframe底部有一个音乐播放器栏,并在上面/后面的iframe中"重写"原始页面。几乎和SMC球员一样。我觉得我很接近,但我是一个jQuery新手。。因此,任何指示都将在事前得到极大的赞赏。
以下是创建无法正常工作的iframe的主要部分。
var oldpage = "<html>" + $("html").html() + "</html>";
$('body').html( "<iframe frameborder='0' id='content' allowtransparency='true' name='content'></iframe>" );
$('#content').contents().find('html').html(oldpage);
$('body').append("<iframe id='stratus' allowtransparency='true' frameborder='0' scrolling='0'>");
我正试图在第1行加载整个原始html。然后创建iframe并尝试将oldbody变量注入到新的iframe#内容中。iframe已创建,但#content iframe的正文为空。
我不知道为什么,但你不能替换整个HTML元素,只能替换它的内容:
// create raw frame
var frame = $('<iframe id="maincontent" style="position:absolute; top: 0; left: 0; width: 50%; height: 50%;"><html></html></iframe>');
// store a copy of current document contents
var copiedHead = $('head').clone();
var copiedBody = $('body').clone();
// empty the current document
$(':not(iframe) body *').remove();
// load the copy into the frame;
// it's not possible to replace the whole HTML element;
// using plain JS DOM function here, since jQuery would strip out any SCRIPT and STYLE tags
frame.load(function(){
$(this).contents().find('html')[0].replaceChild(copiedHead[0] , $(this).contents().find('head')[0]);
$(this).contents().find('html')[0].replaceChild(copiedBody[0] , $(this).contents().find('body')[0]);
}).appendTo('body');
相关文章:
- 使用jQuery从原始页面内容创建iframe
- 动态(重新)创建iframe内容不会重置Chrome中的JS对象
- 如何创建iframe内容的书签
- 如何使用 jquery 动态创建 iframe HTML
- JavaScript 自动创建 iframe
- 是否可以在没有 Cookie 数据的情况下创建 iframe
- 创建 iframe 嵌入并使用模态
- 为什么固定它按钮会创建 iframe
- 使用JavaScript创建IFRAME的最佳实践是什么
- 如何在MVC中的运行时循环中动态创建IFrame
- 动态创建iframe的contentWindow未定义
- 为iframe获取对象null.使用jsdom和所需选项创建iframe
- 为什么<!DOCTYPE>停止javascript创建iFrame
- 两个Javascript无法创建两个iframe,只有最后一个Javascript创建iframe
- 从JQuery创建iframe -属性不工作,为什么不呢?
- 如何在GWT中创建iframe JAVASCRIPT到JAVA
- 动态创建iframe的onload事件在IE中永远不会触发
- javascript创建iframe-自动创建head和body标记
- 只使用javascript创建iframe
- 使用 reactJs 动态创建 iframe