在html页面中获取url参数 [英] Getting the url parameters inside the html page
问题描述
我有一个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中的参数.可以使用Javascript
或jQuery
完成此操作.使用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屋!