Closed Bug 419251 Opened 16 years ago Closed 14 years ago

Replace and innerHTML not working as expected

Categories

(Firefox :: General, defect)

2.0 Branch
x86
Windows XP
defect
Not set
major

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.
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>
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,'&lt;span style="' + style + '"&gt;' + txttoreplace + '&lt;/span&gt;');
>
>    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">&lt;!--
>function __RP_Callback_Helper(str, strCallbackEvent, splitSize, func){var event = null;if (strCallbackEvent){event = document.createEvent('Events');event.initEvent(strCallbackEvent, true, true);}if (str &amp;&amp; str.length &gt; 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 &lt; pluginList.length; count++){var sSrc = '';if (pluginList[count] &amp;&amp; pluginList[count].src)sSrc = pluginList[count].src;if (strCompare.length &gt;= 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);}
>//--&gt;</SCRIPT></HTML>
This does not work in Firefox 2.0 (this is the correct one, both two ones before this attachment should work)
All testcases work for me using Firefox 2.0.0.12 on Windows 2000
It seems it just isn't working on WINXP.  I don't get any errors through Error Console.
Can you retest on your XP machine in safe mode (start menu/program files/mozilla firefox/Mozilla Firefox (safe mode))?
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. 
this happens in safe mode.  Anyone got any ideas?
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
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.

Attachment

General

Creator:
Created:
Updated:
Size: