//iframe processing (insert global style and allow common events to bubble, replace HTML, highly adaptive)$.fn.fniframe =function(Html, isautoheight) { This. each (function() { variframe = This, $iframe= $( This); if(Iframe.localname = = = ' iframe ')) { var$iWindow =$ (Iframe.contentwindow), $iDocument=$ (iframe.contentdocument); varUniqueness =NewDate (). GetTime (); varstyle = ' <style id= ' _iframestyle_ ' >body{font-size:14px;font-family:tahoma,helvetica,arial,sans-serif;margin :0;padding-bottom:1px}body>*:first-child{margin-top:0}</style> '; varhtml = (HTML | | ") + ' <div id=" ' + Uniqueness + ' "hidden></div> '; varAddevevts =function() {$iWindow. MouseDown (function() {$iframe. Parent (). Trigger (' MouseDown '); }); $iWindow. MouseUp (function() {$iframe. Parent (). Trigger (' MouseUp '); }); $iWindow. Click (function() {$iframe. Parent (). Trigger (' Click '); }); }; varIframeload =function(Func) {$iframe. Load (function() {$iDocument=$ (iframe.contentdocument); if($iDocument. Find (' #_iframeStyle_ '). Length = = 0{$iDocument. Find (' Head '). prepend (style); } if(Func && $iDocument. Find (' # ' + uniqueness). Length = = 0) {Func ($iDocument); } }); }; if(Arguments.length = = 0) {//Edit if($iDocument. Find (' #_iframeStyle_ '). Length = = 0{$iDocument. Find (' Head '). prepend (style); Iframeload (); } if(! $iWindow. Data (' Isinit ')) {$iWindow. Data (' Isinit ',true); Addevevts (); } } Else{//Info if($iDocument. Find (' #_iframeStyle_ '). Length = = 0{$iDocument. Find (' Head '). prepend (style); } $iDocument. Find (' Body '). HTML (HTML); if(Isautoheight = = =true) $iWindow. Resize (); Iframeload (function($iDocument) {$iDocument. Find (' Body '). HTML (HTML); if(Isautoheight = = =true) $iWindow. Resize (); }); if(! $iWindow. Data (' Isinit ')) {$iWindow. Data (' Isinit ',true); Addevevts (); if(Isautoheight = = =true) { varFresize =function() {$iDocument=$ (iframe.contentdocument); $iframe. Height (100); varh = $iDocument. Find (' body '). Outerheight (true); $iframe. Height (h); SetTimeout (function() {$iWindow. One (' Resize ',function() {fresize (); }); }, 500); }; Fresize (); } } } } }); return This;};//use case$ (' #xxx '). Find (' iframe '). Fniframe ();//inserts a global style and allows common events to bubble$ (' #xxx '). Find (' iframe '). Fniframe (HTML);//inserts a global style and allows common events to bubble, replace HTML$ (' #xxx '). Find (' iframe '). Fniframe (HTML,true);//Insert global style and allow common events to bubble, replace HTML, highly adaptive
IFRAME iframe processing (insert global style and allow common events to bubble, replace HTML, highly adaptive)