且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在html页面中获取url参数

更新时间:2023-02-23 22:33:07

给出了一个很好的解决方案

A nice solution is given here:

function GetURLParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
        {
            return sParameterName[1];
        }
    }
}​

假设网址是,这就是您可以如何使用此功能的方法, http://dummy.com/?technology=jquery&blog=jquerybyexample:

And this is how you can use this function assuming the URL is, http://dummy.com/?technology=jquery&blog=jquerybyexample:

var tech = GetURLParameter('technology');
var blog = GetURLParameter('blog');`