在html页面中获取url参数 [英] Getting the url parameters inside the html page

查看:1861
本文介绍了在html页面中获取url参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html页面,该页面使用看起来像这样的url加载:

I have a html page which is loaded using a url that looks a little like this:

http://localhost:8080/GisProject/MainService?s=C&o=1

我想在不使用jsp的情况下获取url中的参数.可以使用JavascriptjQuery完成此操作.使用Java服务器的远程计算机.

I would like to obtain the parameters in the url without using a jsp.Can this be done using Javascript or jQuery.I want to test my page using my Node.js local server before deploying it in the remote machine which uses a Java server.

有没有可以让我做到这一点的图书馆.

Is there any library that will allow me to do that.

推荐答案

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

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');`

这篇关于在html页面中获取url参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆