Any HTML after iframe is not executed using document.write

While I was trying to insert an iframe using documnet.write in IE, I got success. But any html code after that is not executed.

document.write("<div>Hello</div><iframe ..../><div>Bye Bye</div>");

Here the string "Bye Bye" is not executed.

For instant verification, you can enter your browser URL

javascript:document.write("<div>Hello</div><iframe ..../><div>Bye Bye</div>");

After trial and error, I found that if I close the iframe tag as follows, it will work.

<iframe ...></iframe> instead of <iframe  ...  />

Now the problem is that "I have no way to change <iframe ../>to <iframe .. ></iframe>." Seek your good advice.

+5
source share
2 answers

document.write, :

markup = "<div>Hello</div><iframe ..../><div>Bye Bye</div>"
markup = markup.replace(/<iframe([^>]*?)\/>/g, '<iframe$1></iframe>')
document.write(markup);
+2

(.. ) document.write, , / ( , ).

, document.write(), , :

document.write=function(str){
    str=str.replace(/<iframe([^>]*?)\/>/ig,'<iframe$1></iframe>');
    return document.writeln(str);
}
+1

All Articles