Why can't I use relative URLs with IE7?

后端 未结 5 2042
臣服心动
臣服心动 2021-01-17 23:50

I\'ve been Googling for a while and can\'t seem to find an answer to this question. My problem is as follows:

For my jquery, I need my links to be relative rather th

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 00:40

    What I do is grab the baseUrl at init, like:

    var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1);
    

    ... and then in my URL handler, strip the baseUrl:

    var url = $(this).attr("href").replace(baseUrl, "");
    

    Also you can check if the href is "normalized" using .support():

    $.support.hrefNormalized
    

    (returns true if the browser makes no modifications when grabbing an href value, so it's currently false in IE.)

提交回复
热议问题