Search code examples
javascripturlencodeencodeurl-encoding

Pound (£) and euro (€) signs encoded wrong in external JavaScript file


I'm trying to encode the £ sign in an external JS file but I keep getting '%EF%BF%BD'. Here's the code in its simplicity:

alert(encodeURIComponent("£"));

The same alert gives me '%C2%A3' on the HTML page that is calling the external JavaScript file. The HTML page has the following character set:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

And I've defined the character set for the external JS file too:

<script type="text/javascript" src="/js/share.js" charset="utf-8"></script>

How can I force the external JavaScript file use UTF-8 encoding?


Solution

  • Fixed the problem by creating a blank JS file with UTF-8 encoding, copying the code in from the original file and replacing the old file with the new file.