How to get values in window.location.href? [duplicate]

百般思念 提交于 2019-12-12 03:59:11

问题


Code:

window.location.href = "Posts?Category=" + sel;

How to get the value in Category page?


回答1:


Try this:

    function getURLParameter(name, urlsearch) {

        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(urlsearch || location.search) || [ , "" ])[1].replace(
                /\+/g, '%20'))
                || null;
    }

    var url = "Posts?Category=1134324";

    alert(getURLParameter('Category', url));

http://jsfiddle.net/kL9DJ/



来源:https://stackoverflow.com/questions/20116962/how-to-get-values-in-window-location-href

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!