msiebuhr / charcod.es

Small webpage for finding the odd unicode char code.
https://charcodes.netlify.app/
ISC License
18 stars 3 forks source link

Permalinks! #12

Closed msiebuhr closed 12 years ago

msiebuhr commented 12 years ago

It's fun to find & share new characters - let's add some kind of permalinks so it's easy to share!

(Also, I should probably buy a dedicated domain for it!)

Munter commented 12 years ago

This should be a bit easier now that I have fixed #17 We could just have the id in the fragment identifier and search for it when ready.

msiebuhr commented 12 years ago

So. I've played with variations over the following

window.onpopstate = function (e) {
    // Shamelessly stolen from MDN
    function loadPageVar (sVar) {
        return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
    }

    var query = loadPageVar("q");
    query = query.replace(/\/$/, ""); // Remove trailing slash

    searchAndShow(query);
    $("#searchField").val(query);
};

It decodes stuff on the form http://charcod.es/?q=QUERY/ and enters in the query-field - which is implicitly searched for when the data is done loading.

But. I can't get FF to fire window.onpopstate when it's loading the page, no matter where I put it. Chrome does it reliably.

My working hypothesis is that I'm hooking in the wrong place, but with my limited knowledge of browser internals, I probably missed something important somewhere else...

msiebuhr commented 12 years ago

Ah. Re-reading the MDN-article on window.onpopstate, yields the following:

Browsers tend to handle the popstate event differently on page load. Chrome and Safari always emit a popstate event on page load, but Firefox doesn't.

msiebuhr commented 12 years ago

Commited draft patch in d6b63d3206f0923bb928853599ee20b0f4dac777 (yes, yes - experimental stuff should go in a branch...)