0

In a section of my webpage is displayed a source code of a HTML (with a <body>, a <head>, ALL that can have a HTML code), and the user can extract the code. I have that code in a text file into a iframe. The problem: Iframe doesn't works in browsers like IE8, because in modern browsers like Chrome, they insert a <pre> within the iframe, and IE8 doesn't.

I need a way for insert the code in the document, without the browser execute the code. Yes, there isn't necessary that the code must be in a text file (.txt), i have seen some people that set a code within a <textarea> and i like that. The idea is that the source code must not be modified, and i have read some PHP solutions, but i can't modify the PHP. I have tried with a <pre> and a <code>, but.. doesn't works, the browser execute the source code anyway, maybe i don't understand the correct use of that tags.

I have read that sometimes is necessary replace some special characters like < for &#60;, could be that the problem? exist a converter that will not affect the final result when be displayed? Thanks! I don't know if i explain me good, i am open to any suggestion (sorry if i sound weird, english is not my native language)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
yukatta
  • 505
  • 2
  • 7
  • 16
  • possible duplicate of [Insert HTML into iframe](http://stackoverflow.com/questions/1565822/insert-html-into-iframe) – Mogsdad Sep 03 '15 at 17:12

1 Answers1

1

With jQuery, you can use AJAX to fetch the file with the source code, and then use the .text(var_with_the_code) in a jQuery object to display HTML source code without "executing" it.

Here is a limited demo in jsFiddle: http://jsfiddle.net/gberger/T3JDJ/

gberger
  • 2,813
  • 3
  • 28
  • 50
  • It works fine in JSfiddle, thanks! but i didn't mention that it was for tumblr, and i put the next code for a test (before the tag): And that didn't work, you can see it [here](http://fruitzo.tumblr.com/sdf) do you know what can be? – yukatta Mar 07 '13 at 20:12
  • 1
    It says this: "XMLHttpRequest cannot load http://static.tumblr.com/36bnqm6/NAFmjb014/chirimoya_beta.txt. Origin http://fruitzo.tumblr.com is not allowed by Access-Control-Allow-Origin." See this question: http://stackoverflow.com/questions/12124538/ajax-access-control-allow-origin-error – gberger Mar 07 '13 at 20:21
  • Ok, i will try to modify the PHP (because in tumblr you can't) or try to upload the file in the same origin (fruitzo.tumblr.com/......) it was very helpful, thanks for your help! – yukatta Mar 07 '13 at 20:52