JQuery - 如何在基于 WebKit 的浏览器(chrome/safari)中将对象附加到 iframe? [英] JQuery - how to append object to iframe in WebKit based browsers (chrome/safari)?

查看:31
本文介绍了JQuery - 如何在基于 WebKit 的浏览器(chrome/safari)中将对象附加到 iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

 <iframe id="iframeId" name="iframeId" src="about:blank" ></iframe><div id="测试">文本

而且我需要将整个对象附加到 iframe(不仅仅是 html()).它在 IE、Firefox 和 Opera 中运行良好,但我无法在 Chrome/Safari 中运行.是否有任何黑客或其他方式,如何将 html 对象放入 iframe,与 WebKit 一起使用?

编辑

我无法克隆该对象(或使用其内部 Html),因为我需要将它与文件输入一起使用,但由于安全限制,我无法复制它.

解决方案

外部HTML.这个例子工作正常:

jQuery.fn.outerHTML = function() {返回 $('<div>').append( this.eq(0).clone() ).html();};$("#iframeId").contents().find("body").html($("#test").outerHTML());$("#test").remove();

--编辑

 <iframe id="iframeId" name="iframeId" src="about:blank" ></iframe><div id="测试">文本

--编辑二

$("#iframeLast").contents().find("body").append($("<form></form>").append($("#inputLast")));

I have this code:

  <script type="text/javascript">
    $(document).ready(function() {
        $("#iframeId").contents().find("body").append($("#test"));
    });
  </script>
  <iframe id="iframeId" name="iframeId" src="about:blank" ></iframe>
  <div id="test">
     Text
  </div>

And i need to append whole object to iframe (not only the html()). It works well in IE, Firefox and Opera, but I can't make it going in Chrome/Safari. Is there any hack or other way, how to put html object into the iframe, working with WebKit?

EDIT

I can't clone the object (or use its inner Html), because I need to use it with file input and I can't copy it due to security restrictions.

解决方案

outerHTML. This example works fine:

jQuery.fn.outerHTML = function() {
    return $('<div>').append( this.eq(0).clone() ).html();
};

$("#iframeId").contents().find("body").html($("#test").outerHTML());
$("#test").remove();

--EDIT

  <script type="text/javascript">
    $(document).ready(function() {
     $("#iframeId").contents().find("body").html($("<div></div>").append($("#test")).html());
    });
  </script>
  <iframe id="iframeId" name="iframeId" src="about:blank" ></iframe>
  <div id="test">
     Text
  </div>

--EDIT II

$("#iframeLast").contents().find("body").append($("<form></form>").append($("#inputLast")));

这篇关于JQuery - 如何在基于 WebKit 的浏览器(chrome/safari)中将对象附加到 iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆