开发者

Slash being escaped in URL

I'm using jquery.history plugin in my web-app and have a problem with '/' being escaped, so for example I need to have following URL generated

/SomeAction#Resource/ResOne

but got

/SomeAction#Resource%F2ResOne

开发者_如何学编程

for loading the URL I use

$.history.load(btn.attr('action-name'));

where btn element has attribute action-name 'Resource/ResOne' (it has '/' symbol in source code)

So the question is how to achieve that '/' symbol will remain in the URL? (this approach is used in gmail when you open on some mail from the inbox, so please don't answer with techniques that use decoding techniques on server side)

Thanks


decodeURIComponent in itself probably won't help. Look at the plugin, and specifically, let's look at the 'locationWrapper'. This is one of the things that are likely being called when you add 'load' a url.

var locationWrapper = {
    put: function(hash, win) {
        (win || window).location.hash = this.encoder(hash);
    },
    get: function(win) {
        var hash = ((win || window).location.hash).replace(/^#/, '');
        try {
            return $.browser.mozilla ? hash : decodeURIComponent(hash);
        }
        catch (error) {
            return hash;
        }
    },
    encoder: encodeURIComponent
};

Notice the encoder part? You'll need to override that somehow, or replace the encoder.. from a quick glance at the code, it doesn't look overly 'extend' friendly. So, according to that code, it doesn't matter if you 'decode' the action-name a million times, it's still going to encode it again.

Edit: just found this on the wiki:

$.history.init(callback, { unescape: true });

It's a configuration option. https://github.com/tkyk/jquery-history-plugin/wiki/How-to-use-the-forward-slash-instead-of-ugly-%27%252F%27

Anyway, good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜