lastlifelost Posted March 8, 2011 Share Posted March 8, 2011 I'm trying to make the following code display the source of a specific block. It works in mosts browsers, but IE is rendering everything on a single line. I can't figure out what I'm missing to make it show properly. Do any of you good fellows have some suggestions? $(function() { $("<pre />", { "html": $("#jsMethod") .html() .replace(/[<>\t]/g, function(m) { return {'<':'<','>':'>','\t':' '}[m]}) + '\n</html>', }).appendTo("#jsMethodSource"); }); http://stweb.ccv.edu/CIS-2140-VO01-V11SP/s...nments/test.htm Link to comment Share on other sites More sharing options...
justsomeguy Posted March 8, 2011 Share Posted March 8, 2011 What's the purpose of the "</html>" in that, and why is there a comma after it? Link to comment Share on other sites More sharing options...
lastlifelost Posted March 8, 2011 Author Share Posted March 8, 2011 Thanks for catching that. It was a hang around from an earlier version of the script. I'm not sure why the comma was there, really. Fixed that: $(function() { $("<pre />", { "html": $("#jsMethod") .html() .replace(/[<>\t]/g, function(m) { return {'<':'<','>':'>','\t':' '}[m]}) }).appendTo("#jsMethodSource"); }); http://stweb.ccv.edu/CIS-2140-VO01-V11SP/s...nments/test.htmIt doesn't look like that was the hang up in IE, though. Am I missing something else in the code? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 8, 2011 Share Posted March 8, 2011 It may have something to do with the line endings in the file, paste the Javascript code directly into a pre tag and see if it displays the same. Link to comment Share on other sites More sharing options...
lastlifelost Posted March 8, 2011 Author Share Posted March 8, 2011 Tried it, that renders just fine. I had a feeling that it was something to do with line carriage returns, but couldn't figure out what to do about it. Is there a way to target IE only then pick up the script line by line and re-render it with each line ending in a \n or even hard-coding in a <br> on each line maybe? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 9, 2011 Share Posted March 9, 2011 You can try splitting the text on a newline character and re-assembling it. IE may transform the text there when the page loads though, I haven't tried to get the contents of a script element before. Link to comment Share on other sites More sharing options...
lastlifelost Posted March 9, 2011 Author Share Posted March 9, 2011 I'll try playing with that option. I feel like there must be some easier answer though. Anybody have other suggestions for what I'm (or what IE is) doing wrong? Link to comment Share on other sites More sharing options...
lastlifelost Posted March 9, 2011 Author Share Posted March 9, 2011 Woke up this morning with the solution in mind. Modified the replace line as follows: .replace(/[<>\t\n]/g, function(m) { return {'<':'<','>':'>','\t':' ','\n':'<br>'}[m]}) It now replaces \n with <br>, fixing the issue without needing to split the string up and reassemble. This fixes the problem I was having in IE. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.