Here is what I am trying but am not sure how to get this working or if it is even possible -
I have an HTML page
MyHTMLPage.htm
and I want tosrc
a Javascript from this HTML file. This is pretty straightforward. I plan to include a<script src = "MyJavascript.js"></script>
tag in my HTML file and that should take care of it.However, I want to create my Javascript file using UTF-16 encoding. So, I plan to use the following tag
<script charset="UTF-16" src="MyJavascript.js"></script>
in my HTML file to take care of thatNow the problem I am really stuck at is how do I create the Javascript using UTF-16 encoding - E.g. let's say my Javascript code is
alert(1);
I created my Javascript file with the contents as\u0061\u006c\u0065\u0072\u0074\u0028\u0031\u0029\u003b
but that does not seem to execute as valid Javascript at runtime.
To summarize, here is what I have -
MyHTMLPage.html
...
...
...
<script charset="UTF-16" src="MyJavascript.js"></script>
...
...
...
MyJavascript.js
\u0061\u006c\u0065\u0072\u0074\u0028\u0031\u0029\u003b
When I open the HTML page in Firefox, I get the error - "Syntax error - Illegal character
" right at the beginning of the MyJavascript.js
file. I have also tried adding the BOM character "\ufeff
" at the beginning of the above Javascript but I still get the same error.
I know I could create my Javascript file as - "alert(1);
" and then save it using UTF-16 encoding using the text editor and then the browser runs it fine however is there a way I could use "\u
" notation (or an alternate escape character) and still get the Javascript to execute fine?
Thanks,