Javascript To Insert Iframe
I'd like to give people the ability to insert a single Javascript line into their site which effectively allows me to insert an IFRAME of a fixed size that contains content from my
Solution 1:
Yes, it is possible. You can use document.createElement("iframe") and then appendChild() or replaceChild() the new element =/ [if you use replaceChild, you define a dummy div that has the width/height of your iframe]
Or am I interpreting your question incorrectly?
Solution 2:
Here is a suedo code for guaranteed insertion and loading of iframe
var __IE__ = navigator.userAgent.indexOf("MSIE") >= 0 ;
var iframe=document.createElement("iframe");
iframe.src="__URL__";
if(document.reayState === "complete" || ( __IE__ && document.readyState === "interactive" )){
document.body.appendChild(iframe);
}else{
if(__IE__){
document.onreadystatechange = function(){
if(document.readyState === "complete"){
document.onreadystatechange = null;
document.body.appendChild(iframe);
}
};
}else{
var callback = function(){
if(document.removeEventListener){
document.removeEventListener("DOMContentLoaded",callback,false);
}
window.onload = function(){};
document.body.appendChild(iframe);
}
if(document.addEventListener){
document.addEventListener("DOMContentLoaded",callback,false);
}
window.onload = callback;
}
}
If document state is loading prefer document.write , else you can use above code.
Post a Comment for "Javascript To Insert Iframe"