javascript - IE8 iframe renders simple text file as HTML , I need raw code -
i have iframes need show codefiles. codefiles have .txt extention , should show code text. works on browsers except ie8. ie8 keeps rendering code files html.
<iframe id="codefile222" width="100%" height="200px" marginheight="0" frameborder="0" src="http://mrsbos.wikispaces.com/file/view/guessnumber.txt" name="codefile222" onload="autoresize('codefile222');changecolor('codefile222')" >
any idea this, make work in ie8
the content-type
http header indicates mime type of resource (a web page, image, or download). html pages, mime type text/html
, , text files, text/plain
.
the server send text/plain;charset=utf-8
text files (as, example, shown in firebug's net panel when performing hard reload of file using ctrl+f5). however, internet explorer, unlike other web browsers, see html in file , second-guess server (microsoft documentation).
because can have security implications, yet microsoft didn't want risk breaking backward compatibility older sites (by making ie's behavior consistent of other browsers), internet explorer 8 , newer support x-content-type-options: nosniff
header disable html detection in case. however, on such site wikispaces, might not have option send header, , in case, header have no effect in internet explorer 6 , 7.
on wikispaces, makes sense use provided source-code formatting feature (see wikitext page):
[[code format="javascript"]] alert('hello, world'); [[code]]
and if want store code on separate page, can include page people supposed read (wikispaces include page). called transclusion:
[[include page="pagename"]]
failing that, option may html-escape code (using few text replacements) , insert between <pre></pre>
. uploading html file (file extension of .htm
or .html
). purpose of explanation, here simple javascript function html escaping:
function htmlescape(text) { // absolutely necessary text = text.replace(/&/g, '&'); // has go first text = text.replace(/</g, '<'); // not needed specific case, yet include text = text.replace(/>/g, '>'); text = text.replace(/"/g, '"'); text = text.replace(/'/g, '''); // ''' ok in xhtml , in html5 return text; }
Comments
Post a Comment