0

I am reading some pages that don't display correctly some UTF-8 characters. For example this page shows – instead of en dash (–).

Others:

showing ’ instead of

showing ‘ instead of (see this page)

Is it possible to fix this problem in a bookmarklet? If yes, then how?

BearCode
  • 2,734
  • 6
  • 34
  • 37

2 Answers2

0

With a bookmarklet, no. Unfortunately most browsers don't provide a method to change the page encoding with javascript. You may try adding a meta tag to affect the encoding but this may not work with all browsers (google "meta tag encoding"). This is primarily a server issue - the web server sent the wrong encoding header for the page.

However, if you want a menu item that you can invoke from the browser to change the encoding (which is basically what a bookmarklet is anyway) you can simply invoke the encoding menu and change it to UTF-8. On IE8 it's Page->Encoding->UTF8, on Chrome it's Menu->Tools->Encoding->UTF8. Google around for other browsers.

slebetman
  • 109,858
  • 19
  • 140
  • 171
-1

I found the solution, being helped by the other question:

javascript:
function htmlreplace(a, b, element) {    
    if (!element) element = document.body;    
    var nodes = element.childNodes;
    for (var n=0; n<nodes.length; n++) {
        if (nodes[n].nodeType == Node.TEXT_NODE) {
            var r = new RegExp(a, 'gi');
            nodes[n].textContent = nodes[n].textContent.replace(r, b);
        } else {
            htmlreplace(a, b, nodes[n]);
        }
    }
}
htmlreplace("–","–");
htmlreplace("’","’");
htmlreplace("‘","‘");
htmlreplace("“","“");
htmlreplace("„","„");

Awesome!

Community
  • 1
  • 1
BearCode
  • 2,734
  • 6
  • 34
  • 37