Closed
Bug 419251
Opened 16 years ago
Closed 14 years ago
Replace and innerHTML not working as expected
Categories
(Firefox :: General, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: henry.fai.hang.chan, Unassigned)
Details
(Whiteboard: [CLOSEME 2010-07-30])
Attachments
(3 files)
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 I built a text color changer. somehow it doesn't work in firefox as expected (see testcase) Reproducible: Always Steps to Reproduce: 1.Select text 2.click make red. 3. Actual Results: Nothing happens Expected Results: the selected text turns red. There is a workaround: add this line to the script: document.getElementById('div').innerHTML = ''; before document.getElementById('div').innerHTML = txtreplaced; -------------------------------------------------------------------- Also (repeated or else won't work) document.getElementById('div').innerHTML = txtreplaced; document.getElementById('div').innerHTML = txtreplaced; Will get the code running properly.
Reporter | ||
Comment 1•16 years ago
|
||
Reporter | ||
Comment 2•16 years ago
|
||
Reporter | ||
Comment 3•16 years ago
|
||
Comment on attachment 305298 [details]
This does not work in Firefox 2.0
<script language=javascript>
function getSelText(style){
var txttoreplace = '';
if (window.getSelection)
{
txttoreplace = window.getSelection();
}
else if (document.getSelection)
{
txttoreplace = document.getSelection();
}
else if (document.selection)
{
txttoreplace = document.selection.createRange().text;
}
else return;
txtreplaced = document.getElementById('div').innerHTML.replace(txttoreplace,'<span style="' + style + '">' + txttoreplace + '</span>');
document.getElementById('div').innerHTML = txtreplaced;
;
}
</script>
<input type="button" value="make red" onmousedown="getSelText('color: red');">
<div id="div">hello</div>
Reporter | ||
Comment 4•16 years ago
|
||
Comment on attachment 305298 [details] This does not work in Firefox 2.0 ><HTML><HEAD><SCRIPT language="javascript"> >function getSelText(style){ > var txttoreplace = ''; > if (window.getSelection) > { > txttoreplace = window.getSelection(); > } > else if (document.getSelection) > { > txttoreplace = document.getSelection(); > } > else if (document.selection) > { > txttoreplace = document.selection.createRange().text; > } > else return; > > txtreplaced = document.getElementById('div').innerHTML.replace(txttoreplace,'<span style="' + style + '">' + txttoreplace + '</span>'); > > document.getElementById('div').innerHTML = txtreplaced; >; >} ></SCRIPT><script xmlns="http://www.w3.org/1999/xhtml" src="chrome://skype_ff_toolbar_win/content/injection_graph_func.js" id="injection_graph_func" charset="utf-8"/></HEAD><BODY><INPUT type="button" onmousedown="getSelText('color: red');" value="make red"/> ><DIV id="div"><SPAN style="color: red;"/>he<SPAN style="color: red;">llo</SPAN></DIV> ></BODY><SCRIPT type="text/javascript"><!-- >function __RP_Callback_Helper(str, strCallbackEvent, splitSize, func){var event = null;if (strCallbackEvent){event = document.createEvent('Events');event.initEvent(strCallbackEvent, true, true);}if (str && str.length > 0){var splitList = str.split('|');var strCompare = str;if (splitList.length == splitSize)strCompare = splitList[splitSize-1];var pluginList = document.plugins;for (var count = 0; count < pluginList.length; count++){var sSrc = '';if (pluginList[count] && pluginList[count].src)sSrc = pluginList[count].src;if (strCompare.length >= sSrc.length){if (strCompare.indexOf(sSrc) != -1){func(str, count, pluginList, splitList);break;}}}}if (strCallbackEvent)document.body.dispatchEvent(event);}function __RP_Coord_Callback(str){var func = function(str, index, pluginList, splitList){pluginList[index].__RP_Coord_Callback = str;pluginList[index].__RP_Coord_Callback_Left = splitList[0];pluginList[index].__RP_Coord_Callback_Top = splitList[1];pluginList[index].__RP_Coord_Callback_Right = splitList[2];pluginList[index].__RP_Coord_Callback_Bottom = splitList[3];};__RP_Callback_Helper(str, 'rp-js-coord-callback', 5, func);}function __RP_Url_Callback(str){var func = function(str, index, pluginList, splitList){pluginList[index].__RP_Url_Callback = str;pluginList[index].__RP_Url_Callback_Vid = splitList[0];pluginList[index].__RP_Url_Callback_Parent = splitList[1];};__RP_Callback_Helper(str, 'rp-js-url-callback', 3, func);}function __RP_TotalBytes_Callback(str){var func = function(str, index, pluginList, splitList){pluginList[index].__RP_TotalBytes_Callback = str;pluginList[index].__RP_TotalBytes_Callback_Bytes = splitList[0];};__RP_Callback_Helper(str, null, 2, func);}function __RP_Connection_Callback(str){var func = function(str, index, pluginList, splitList){pluginList[index].__RP_Connection_Callback = str;pluginList[index].__RP_Connection_Callback_Url = splitList[0];};__RP_Callback_Helper(str, null, 2, func);} >//--></SCRIPT></HTML>
Reporter | ||
Comment 5•16 years ago
|
||
This does not work in Firefox 2.0 (this is the correct one, both two ones before this attachment should work)
Comment 6•16 years ago
|
||
All testcases work for me using Firefox 2.0.0.12 on Windows 2000
Reporter | ||
Comment 7•16 years ago
|
||
It seems it just isn't working on WINXP. I don't get any errors through Error Console.
Comment 8•16 years ago
|
||
Can you retest on your XP machine in safe mode (start menu/program files/mozilla firefox/Mozilla Firefox (safe mode))?
Reporter | ||
Comment 9•16 years ago
|
||
this is solved in Minefield. This also happens in safe mode. I'm trying to use document.open() and then, after, use document.close(), as used in bug 383022. I suspect both bugs caused by the same JavaScript. The other works with the extra codes.
Reporter | ||
Comment 10•16 years ago
|
||
this happens in safe mode. Anyone got any ideas?
Comment 11•14 years ago
|
||
This bug was originally reported on Firefox 2.x or older, which is no longer supported and will not be receiving any more updates. I strongly suggest that you update to Firefox 3.6.6 or later, update your plugins (flash, adobe, etc.), and retest in a new profile. If you still see the issue with the updated Firefox, please post here. Otherwise, please close as RESOLVED > WORKSFORME http://www.mozilla.com http://support.mozilla.com/kb/Managing+profiles http://support.mozilla.com/kb/Safe+mode
Whiteboard: [CLOSEME 2010-07-30]
Version: unspecified → 2.0 Branch
Reporter | ||
Updated•14 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•