Jump to content

Viewsource code not working properly in IE


lastlifelost

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...