Jump to content

How to save the changed page after using selection.createRange


hpdp

Recommended Posts

Hi, I have a web page. I can select a word and change the color of that word. Butthe problem is when I view the source of that page from the browser, I stillsee the original html source code instead of the changed one. My example code is: (only works at IE browser)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"   "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head><title>highlight</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script language="javascript" type="text/javascript">function findText(snippet) {var userSelectedRange = document.selection.createRange();var selectedText = userSelectedRange.textvar selectedHtmlText = userSelectedRange.htmlText;var replaceText = '<span class="'+snippet+'">'+selectedText+'</span>';alert('text='+selectedText);alert('html='+selectedHtmlText);var newSourceCode, count=0;newSourceCode= document.body.innerHTML;re = new RegExp(selectedHtmlText, "gi");newSourceCode= newSourceCode.replace(re,replaceText);document.body.innerHTML = newSourceCode;}</script><style type="text/css">.highlight {background:#ff0;color#00f;}.blue {color:blue;}.red {color:red;}.orange {color: orange;}.purple {color: purple;}</style></head><body><form action="" method="" name="form1"><div>		<button type="button" id="red" value="red" onclick="findText(document.getElementById('red').value)">red</button>  		<button type="button" id="blue" value="blue" onclick="findText(document.getElementById('blue').value)">blue</button></div></form><br>A <span class="orange" id="1">strain</span> of <span class="red">Stachybotrys</span> <span class="orange">chartarum</span> was <span class="blue">recently</span> <span cl######="orange">isolated</span> from the <span class="orange">lung</span> of a <span class="purple">patient</span> in <span class="orange">Texas</span> .<br>A <span class="orange" id="1">strain</span> of <span class="red">Stachybotrys</span> <span class="orange">chartarum</span> was <span class="blue">recently</span> <span cl######="orange">isolated</span> from the <span class="orange">lung</span> of a <span class="purple">patient</span> in <span class="orange">Texas</span> .</body></html>

Thanks for any help on this problem!!!!

Link to comment
Share on other sites

I would imagine changes like that with Javascript are saved in the browsers cache, or can be saved on the users machine with cookies. I think expecting Javascript to permanetly overwrite a sites CSS could be a bit problematic in the real world, eh? I''m sure other will elaborate more on the details, but I believe that is the short and skinny of it.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...