Switch to full style
JQuery Examples
Post a reply

get url, title and url sent parameters with JQuery

Thu Jan 10, 2013 12:45 am

Get window URL, page title and URL parameters
javascript code
<html> 
<head>
<title>print URL, Title and URL sent parameters</title>

<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
Note you can download the JQuery package instead of using Google version. -->
<script src="jquery-1.8.3.js"></script>
<script>
$(document).ready(function(){
$("button#btn1").click(function(){
//For:
//http://localhost/JQuery/QueryStart.html?username=mess&age=34&address=USA

// Get Parameter value with name = username
$("div").html($.urlParam('username')+"<br/>");
// Get Parameter value with name = age
$("div").append($.urlParam('age')+"<br/>");
// Get Parameter value with name = address
$("div").append($.urlParam('address')+"<br/>");
});

$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}

$("button#btn2").click(function(){
var URL = window.location.href;

$("div").html('<strong>' + URL + '</strong>');

});

$("button#btn3").click(function(){

var title = $(document).attr('title');

$("div").html('<strong>' + title + '</strong>');
});


});
</script>
</head>
<body>

<p style="background:#1414A4;color:yellow;width='50';"
width="200"><b>Show Url Parameters</b></p><br>
<div></div>
<button id="btn1">Show Parameters</button>
<button id="btn2">Show URL</button>
<button id="btn3">Show Page Title</button>
</body>
</html>




Post a reply
  Related Posts  to : get url, title and url sent parameters with JQuery
 Post parameters using JQuery     -  
 Get values of Form parameters using JQuery     -  
 How to change this title • ?     -  
 remove page title     -  
 Encoding parameters in URL     -  
 Reference Parameters     -  
 Method Parameters,,,is it by value or reference???     -  
 Function with default parameters     -  
 Send parameters using HTTP GET     -  
 method with a variable number of parameters     -  

Topic Tags

JQuery Validation