optikalefx Posted April 19, 2008 Share Posted April 19, 2008 so i have a webpage that basically when you click a button it replaces BODY with a textnode of the innerHTML. Basically a view source. Problem is, that it shows all the HTML gumbled up. So how could i put in line breaks? Maybe make use of the splitText function? Link to comment https://forums.phpfreaks.com/topic/101813-using-n/ Share on other sites More sharing options...
RichardRotterdam Posted April 19, 2008 Share Posted April 19, 2008 Ah i runned into the same trouble one time. Just use a Textarea the put your source in it will display fine Link to comment https://forums.phpfreaks.com/topic/101813-using-n/#findComment-521194 Share on other sites More sharing options...
optikalefx Posted April 19, 2008 Author Share Posted April 19, 2008 ok that works sort of. But it only line breaks if i had line broke in the code by hitting enter. Is there a snippet that would loop thru the code and if it found > it would replace it with >/n so that all tags would be be on a new line? Link to comment https://forums.phpfreaks.com/topic/101813-using-n/#findComment-521251 Share on other sites More sharing options...
RichardRotterdam Posted April 19, 2008 Share Posted April 19, 2008 uhm can i conclude that you have a > character that you want to replace with a \n if that is so why not use string replace function Link to comment https://forums.phpfreaks.com/topic/101813-using-n/#findComment-521523 Share on other sites More sharing options...
optikalefx Posted April 20, 2008 Author Share Posted April 20, 2008 when i do str.replace("",""); its only replacing the first occurance. any ideas? Link to comment https://forums.phpfreaks.com/topic/101813-using-n/#findComment-521907 Share on other sites More sharing options...
optikalefx Posted April 20, 2008 Author Share Posted April 20, 2008 ok this is making me angry function viewHTML() { var html = editDoc.body.innerHTML; html = html.replace(/\n/g,""); html = html.replace(/>/g,">\n\r"); var view = editDoc.createTextNode(html); //view.style.width = editDoc.body.clientWidth; //view.style.height = editDoc.body.clientHeight; //view.innerHTML = html; editDoc.body.parentNode.replaceChild(view,editDoc.body); } so the replace functions do work to replace all occurences of a character. BUT id like it not to be a textarea, because im useing document.designMode as well. so i want it to be in a DIV or something. So i trie dthis function viewHTML() { var html = editDoc.body.innerHTML; html = html.replace(/\n/g,""); html = html.replace(/>/g,">\n\r"); var view = editDoc.createElement('DIV'); view.style.width = editDoc.body.clientWidth; view.style.height = editDoc.body.clientHeight; view.innerHTML = html; editDoc.body.parentNode.replaceChild(view,editDoc.body); } but that just recreates the body so i escaped it function viewHTML() { var html = editDoc.body.innerHTML; html = html.replace(/\n/g,""); html = html.replace(/>/g,">\n\r"); var view = editDoc.createElement('DIV'); view.style.width = editDoc.body.clientWidth; view.style.height = editDoc.body.clientHeight; view.innerHTML = escape(html); editDoc.body.parentNode.replaceChild(view,editDoc.body); } but that puts a ton of %20s and stuff and doesnt react to the replaces \n's an ahhhhhh i just want Link to comment https://forums.phpfreaks.com/topic/101813-using-n/#findComment-521928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.