How To Become Electrical Flow Url, Parameters In Addition To Hash Tag Using Jquery In Addition To Javascript
Tuesday, September 18, 2018
Add Comment
While dealing amongst electrical flow URL, many fourth dimension y'all desire to know what is the electrical flow URL path, What are the parameters, in addition to what is the hashtag on URL. The hash tag is pretty of import if y'all are implementing tab construction using HTML in addition to JQuery. To avoid confusion, let's stimulate got an lawsuit of URL: https://noobsjava.blogspot.com//search?q=top-5-java-programming-books-best-good#ixzz2PGmDFlPd , inward this lawsuit ixzz2PGmDFlPd, is a hash tag. Now, both JavaScript in addition to JQuery provides a convenient means to remember electrical flow URL inward the cast of window.location object. You tin exercise 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, in addition to window.location.hash to acquire a hash tag from electrical flow URL. If y'all similar to exercise JQuery in addition to thence y'all tin acquire a window.location every bit JQuery object in addition to remember relevant properties using attr() function.
If y'all are absolutely novel inward JQuery in addition to unaware of the ability of 1 of the most pop JavaScript framework, Head First JQuery is a expert starting point. Being a fan of the caput showtime book, I ever approach a novel technology scientific discipline past times a Head showtime title, it helped to larn a lot inward brusk time, without spending fourth dimension inward picayune examples.
By the way, In this spider web tutorial, nosotros are going to remember electrical flow URL in addition to hash tag using JavaScript in addition to JQuery.
If y'all are absolutely novel inward JQuery in addition to unaware of the ability of 1 of the most pop JavaScript framework, Head First JQuery is a expert starting point. Being a fan of the caput showtime book, I ever approach a novel technology scientific discipline past times a Head showtime title, it helped to larn a lot inward brusk time, without spending fourth dimension inward picayune examples.
By the way, In this spider web tutorial, nosotros are going to remember electrical flow URL in addition to hash tag using JavaScript in addition to JQuery.
How to uncovering electrical flow URL using JavaScript in addition to JQuery.
In JavaScript, only exercise window.location.href, in addition to inward JQuery exercise code $(location).attr('href'), both volition render electrical flow URL. In our around other lawsuit URL http://localhost:8080/testapp/, here window.location.href volition render consummate URL, but if y'all are only interested inward the path, in addition to thence y'all tin exercise 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 y'all desire to acquire them using JQuery in addition to thence exercise next code
var URL = $(location).attr('href');
var PATH = $(location).attr('pathname')
In adjacent section, nosotros volition larn how to acquire hash tag using JavaScript in addition to JQuery.
How to acquire Hashtag from electrical flow URL using JavaScript in addition to JQuery.
Hash tags are String amongst prefix # (hash) inward URL. If y'all are using tab-based UI in addition to using div to correspond dissimilar tab, in addition to if y'all are electrical flow URL, when user is inward tab2 is http://localhost:8080/testapp#tab2, in addition to thence y'all tin remember tab2 past times using window.location.hash object. This volition render only "tab2". You tin too wrap same code inward 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 in addition to JQuery code. We stimulate got pose the JQuery code inward $(document).ready(), thence it volition move executed when page volition move loaded.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JQuery in addition to JavaScript lawsuit to acquire electrical flow URL amongst parameters </title>
</head>
<body>
<div id="choice">
<h2>JQuery Code for getting electrical flow URL in addition to Hash </h2>
</div>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
//windo.location.pathname volition seat y'all 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 in addition to hash value using JavaScript in addition to jQuery. It's real easy, y'all only take away to know nigh window.location Javascript object, but if y'all are jQuery fan, in addition to desire to avoid cross browser hassles, in addition to thence y'all tin too stimulate got wages of jQuery 1 liner $(location).attr("href") to acquire electrical flow URL or whatever attribute from place object.
Further Reading
here)
0 Response to "How To Become Electrical Flow Url, Parameters In Addition To Hash Tag Using Jquery In Addition To Javascript"
Post a Comment