我需要根据网址了解我所在的网页。
当我使用$(location).attr('href')
时,我会得到一个很长的网址:
http://localhost:8181/research/gadgets/ifr?container=default&mid=0&nocache=0&country=ALL&lang=ALL&view=default&nerwVersion=~project.version~&url=http%3A%2F%2Flocalhost%3A8181%2Fresearch%2Fnerw-gadgets%2FCompanyDetails%2FCompanyDetails.xml&oaaParent=http%3A%2F%2Flocalhost%3A8181
浏览器中的URL如下所示:
http://localhost:8181/research/?view=home
我如何获得view = home位?
答案 0 :(得分:0)
试试这个: -
function getQuerystring(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(window.location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
Usage getQuerystring("view");