Skip to content

Instantly share code, notes, and snippets.

@olamedia
Created May 16, 2011 13:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olamedia/974401 to your computer and use it in GitHub Desktop.
Save olamedia/974401 to your computer and use it in GitHub Desktop.
core.js
(function(window, undefined) {
var document = window.document, $ = window.jQuery;
var iframe = function(element) {
console.log('make jquery iframe element');
var iframe = $('<iframe frameborder=1 style="border: solid 1px #f00;" width="800" height="400"></iframe>');
console.log('append iframe to body');
$(element).after(iframe);
//$(element).hide();
// $("body").append(iframe);
return iframe;
}
/*var designMode = function(element) {
try {
element.designMode = "on";
} catch (e) {
}
if ("on" === element.designMode) {
return true;
}
return false;
}*/
/*$.fn.designMode = function() {
console.log('design mode');
return designMode(this);
};*/
$.fn.iframe = function() {
console.log('make iframe');
return iframe(this);
};
// focus = $.fn.focus;
$.fn.getDocument = function() {
var e = this.get(0);
if (e.nodeName.toLowerCase() === 'iframe') {
console.log('contentWindow document');
return e.contentWindow.document;
}
console.log('default document');
return document;
}
$.fn.viewSource = function(){
var e = this.get(0);
var body = $(e);
if (e.nodeName.toLowerCase() === 'iframe') {
body = $(body.getDocument()).find('body');
}
body.text(body.html());
return this;
}
$.fn.viewHtml = function(){
var e = this.get(0);
var body = $(e);
if (e.nodeName.toLowerCase() === 'iframe') {
body = $(body.getDocument()).find('body');
}
body.html(body.text());
return this;
}
$.fn.print = function(){
this.getWindow().print();
}
$.fn.getWindow = function() {
console.log(this);
var e = this.get(0);
if (e.nodeName.toLowerCase() === 'iframe') {
return e.contentWindow;
}
return window;
}
}(window));
<script type="text/javascript">
$(function(){
var iframe = $("#content").iframe();
var idoc = iframe.getDocument();
$(idoc).find('body').html($("#content").html());
idoc.designMode = "on";
var idoc = iframe.getDocument();
iframe.viewSource();
iframe.viewHtml();
$(iframe.getWindow()).focus();
});
</script>
@olamedia
Copy link
Author

<script type="text/javascript"> $(function(){ var iframe = $("#content").iframe(); var idoc = iframe.getDocument(); $(idoc).find('body').html($("#content").html()); idoc.designMode = "on"; var idoc = iframe.getDocument(); $(iframe.getWindow()).focus(); }); </script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment