How To Become Electrical Current Url, Parameters Too Hash Tag Using Jquery Too Javascript
While dealing amongst electrical flow URL, many fourth dimension you lot desire to know what is the electrical flow URL path, What are the parameters, together with what is the hashtag on URL. The hash tag is pretty of import if you lot are implementing tab construction using HTML together with JQuery. To avoid confusion, let's cause got an instance of URL: https://sarjanabelajarjava.blogspot.com//search?q=top-5-java-programming-books-best-good#ixzz2PGmDFlPd , inwards this instance ixzz2PGmDFlPd, is a hash tag. Now, both JavaScript together with JQuery provides a convenient means to shout out back electrical flow URL inwards the cast of window.location object. You tin dismiss usage diverse properties of the window.location JavaScript object e.g. window.location.href to acquire consummate URL, window.location.pathname to acquire the electrical flow path, together with window.location.hash to acquire a hash tag from electrical flow URL. If you lot similar to usage JQuery together with thus you lot tin dismiss acquire a window.location every bit JQuery object together with shout out back relevant properties using attr() function.
If you lot are absolutely novel inwards JQuery together with unaware of the ability of 1 of the most pop JavaScript framework, Head First JQuery is a proficient starting point. Being a fan of the caput starting fourth dimension book, I ever approach a novel technology scientific discipline yesteryear a Head starting fourth dimension title, it helped to larn a lot inwards brusque time, without spending fourth dimension inwards lilliputian examples.
By the way, In this spider web tutorial, nosotros are going to shout out back electrical flow URL together with hash tag using JavaScript together with JQuery.
If you lot are absolutely novel inwards JQuery together with unaware of the ability of 1 of the most pop JavaScript framework, Head First JQuery is a proficient starting point. Being a fan of the caput starting fourth dimension book, I ever approach a novel technology scientific discipline yesteryear a Head starting fourth dimension title, it helped to larn a lot inwards brusque time, without spending fourth dimension inwards lilliputian examples.
By the way, In this spider web tutorial, nosotros are going to shout out back electrical flow URL together with hash tag using JavaScript together with JQuery.
How to uncovering electrical flow URL using JavaScript together with JQuery.
In JavaScript, but usage window.location.href, together with inwards JQuery usage code $(location).attr('href'), both volition render electrical flow URL. In our roughly other instance URL http://localhost:8080/testapp/, here window.location.href volition render consummate URL, but if you lot are but interested inwards the path, together with thus you lot tin dismiss usage window.location.path, which volition render /testapp.
URL : http://localhost:8080/testapp/
window.location.path = /testapp/
window.location.href = http://localhost:8080/testapp/
and if you lot desire to acquire them using JQuery together with thus usage next code
var URL = $(location).attr('href');
var PATH = $(location).attr('pathname')
In side yesteryear side section, nosotros volition larn how to acquire hash tag using JavaScript together with JQuery.
How to acquire Hashtag from electrical flow URL using JavaScript together with JQuery.
Hash tags are String amongst prefix # (hash) inwards URL. If you lot are using tab-based UI together with using div to stand upwardly for dissimilar tab, together with if you lot are electrical flow URL, when user is inwards tab2 is http://localhost:8080/testapp#tab2, together with thus you lot tin dismiss shout out back tab2 yesteryear using window.location.hash object. This volition render but "tab2". You tin dismiss likewise wrap same code inwards JQuery using shortcut $(). Here is the code :
URL : http://localhost:8080/testapp#tab2
window.location.hash = tab2
var hash = $(location).attr('hash');
and hither is the HTML page, which combines all these JavaScript together with JQuery code. We cause got pose the JQuery code inwards $(document).ready(), thus it volition endure executed when page volition endure loaded.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JQuery together with JavaScript instance to acquire electrical flow URL amongst parameters </title>
</head>
<body>
<div id="choice">
<h2>JQuery Code for getting electrical flow URL together with Hash </h2>
</div>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
//windo.location.pathname volition plow over you lot path, afterward http://
var path = window.location.pathname;
alert("window.location.pathname : " + path);
var href = window.location.href;
alert("window.location.href : " + href);
var hash = window.location.hash;
alert("window.location.hash : " + hash);
$(document).ready(function(){
//JQuery code for getting electrical flow URL
var URL = $(location).attr('href');
alert("Current URL Using JQuery : " + URL);
});
</script>
</body>
</html>
That's all on How to uncovering electrical flow URL, path together with hash value using JavaScript together with jQuery. It's real easy, you lot but require to know close window.location Javascript object, but if you lot are jQuery fan, together with desire to avoid cross browser hassles, together with thus you lot tin dismiss likewise cause got payoff of jQuery 1 liner $(location).attr("href") to acquire electrical flow URL or whatever attribute from place object.
Further Reading
here)
Belum ada Komentar untuk "How To Become Electrical Current Url, Parameters Too Hash Tag Using Jquery Too Javascript"
Posting Komentar