This time I will bring you jquery to get url and url parameters (with code). What are the precautions for jquery to get url and url parameters? The following is a practical case, let's take a look.
1. It is very simple to get the url with jquery. The code is as follows
window.location.href;
window object, no knowledge of jquery
2. jquery is more complicated to obtain url parameters, andregular expressions are used, so it is important to learn javascript regular expressions
First, let’s look at how to get a certain parameter in the url simply through javascript.function getUrlParam(name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r!=null) return unescape(r[2]); return null; //返回参数值 }
getUrlParam('cid');
(function($){ $.getUrlParam = function(name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r!=null) return unescape(r[2]); return null; } })(jQuery);
$.getUrlParam('cid');
How to deal with page anchor failure in iframe
Detailed explanation of the steps to obtain the document object in iframe
The above is the detailed content of jquery gets url and url parameters (with code). For more information, please follow other related articles on the PHP Chinese website!