JQuery - how to add object to iframe in WebKit based browsers (chrome / safari)?
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 add the whole object to the iframe (not just html ()). It works well in IE, Firefox and Opera, but I can't seem to do it in Chrome / Safari. Is there any hack or other way how to put the html object in an iframe while working with WebKit?
EDIT
I cannot clone the object (or use its internal Html) because I need to use it with file input and I cannot copy it due to security restrictions.
+2
source to share
1 answer
outerHTML . This example works great:
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")));
+7
source to share