如何替换€(how to replace € into € with javascript?)

我试图解决这个论坛的HTML实体显示不正确。 因为所有者是mia,我正在尝试使用扩展名来执行此操作。

我在屏幕上看到的是:

euro:€ pound:£

与萤火虫html DOM的视图

我的代码:

GM_log('before text= '+text); text.replace( /amp;/gi, function( $0 ) { GM_log('$0= '+$0); fix=""; return fix; }); GM_log(' after text= '+text);

其中返回:

before text= euro: &amp;#8364; <br>pound: &amp;#163; $0= amp; $0= amp; after text= euro: &amp;#8364; <br>pound: &amp;#163;

所以我的代码似乎正在工作,直到它必须替换。

那些矩形阻止它? 我做错什么了吗?

如果是的话,我该如何解决这个问题?

谢谢。

i'm trying to fix this forum where html entities are not displayed correctly. since the owner is m.i.a. i'm trying to do this with an extension.

what i see on my screen:

euro:&#8364; pound:&#163;

view of the html DOM with firebug

my code:

GM_log('before text= '+text); text.replace( /amp;/gi, function( $0 ) { GM_log('$0= '+$0); fix=""; return fix; }); GM_log(' after text= '+text);

which returns:

before text= euro: &amp;#8364; <br>pound: &amp;#163; $0= amp; $0= amp; after text= euro: &amp;#8364; <br>pound: &amp;#163;

so my code seems to be working until the point it has to replace.

are those rectangles preventing it? did i do something wrong?

and if so how can i fix this?

thanks.

最满意答案

您忘记了分配replace结果:

text = text.replace(...);

You forgot to assign the result of replace:

text = text.replace(...);如何替换&#8364;(how to replace &#8364; into € with javascript?)

我试图解决这个论坛的HTML实体显示不正确。 因为所有者是mia,我正在尝试使用扩展名来执行此操作。

我在屏幕上看到的是:

euro:&#8364; pound:&#163;

与萤火虫html DOM的视图

我的代码:

GM_log('before text= '+text); text.replace( /amp;/gi, function( $0 ) { GM_log('$0= '+$0); fix=""; return fix; }); GM_log(' after text= '+text);

其中返回:

before text= euro: &amp;#8364; <br>pound: &amp;#163; $0= amp; $0= amp; after text= euro: &amp;#8364; <br>pound: &amp;#163;

所以我的代码似乎正在工作,直到它必须替换。

那些矩形阻止它? 我做错什么了吗?

如果是的话,我该如何解决这个问题?

谢谢。

i'm trying to fix this forum where html entities are not displayed correctly. since the owner is m.i.a. i'm trying to do this with an extension.

what i see on my screen:

euro:&#8364; pound:&#163;

view of the html DOM with firebug

my code:

GM_log('before text= '+text); text.replace( /amp;/gi, function( $0 ) { GM_log('$0= '+$0); fix=""; return fix; }); GM_log(' after text= '+text);

which returns:

before text= euro: &amp;#8364; <br>pound: &amp;#163; $0= amp; $0= amp; after text= euro: &amp;#8364; <br>pound: &amp;#163;

so my code seems to be working until the point it has to replace.

are those rectangles preventing it? did i do something wrong?

and if so how can i fix this?

thanks.

最满意答案

您忘记了分配replace结果:

text = text.replace(...);

You forgot to assign the result of replace:

text = text.replace(...);