How To Become Electrical Flow Url, Parameters Together With Hash Tag Using Jquery Together With Javascript
While dealing alongside electrical flow URL, many fourth dimension y'all desire to know what is the electrical flow URL path, What are the parameters, as well as what is the hashtag on URL. The hash tag is pretty of import if y'all are implementing tab construction using HTML as well as JQuery. To avoid confusion, let's accept an lawsuit of URL: harus di isi/search?q=top-5-java-programming-books-best-good#ixzz2PGmDFlPd , inward this lawsuit ixzz2PGmDFlPd, is a hash tag. Now, both JavaScript as well as JQuery provides a convenient means to recall electrical flow URL inward the shape of window.location object. You tin utilization 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, as well as window.location.hash to acquire a hash tag from electrical flow URL. If y'all similar to utilization JQuery as well as thence y'all tin acquire a window.location every bit JQuery object as well as recall relevant properties using attr() function.
If y'all are absolutely novel inward JQuery as well as unaware of the ability of 1 of the most pop JavaScript framework, Head First JQuery is a practiced starting point. Being a fan of the caput commencement book, I e'er approach a novel technology scientific discipline past times a Head commencement title, it helped to acquire a lot inward brusque time, without spending fourth dimension inward niggling examples.
By the way, In this spider web tutorial, nosotros are going to recall electrical flow URL as well as hash tag using JavaScript as well as JQuery.
If y'all are absolutely novel inward JQuery as well as unaware of the ability of 1 of the most pop JavaScript framework, Head First JQuery is a practiced starting point. Being a fan of the caput commencement book, I e'er approach a novel technology scientific discipline past times a Head commencement title, it helped to acquire a lot inward brusque time, without spending fourth dimension inward niggling examples.
By the way, In this spider web tutorial, nosotros are going to recall electrical flow URL as well as hash tag using JavaScript as well as JQuery.
How to uncovering electrical flow URL using JavaScript as well as JQuery.
In JavaScript, simply utilization window.location.href, as well as inward JQuery utilization code $(location).attr('href'), both volition render electrical flow URL. In our roughly other lawsuit URL http://localhost:8080/testapp/, here window.location.href volition render consummate URL, but if y'all are simply interested inward the path, as well as thence y'all tin utilization 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 as well as thence utilization next code
var URL = $(location).attr('href');
var PATH = $(location).attr('pathname')
In adjacent section, nosotros volition acquire how to acquire hash tag using JavaScript as well as JQuery.
How to acquire Hashtag from electrical flow URL using JavaScript as well as JQuery.
Hash tags are String alongside prefix # (hash) inward URL. If y'all are using tab-based UI as well as using div to stand upwards for unlike tab, as well as if y'all are electrical flow URL, when user is inward tab2 is http://localhost:8080/testapp#tab2, as well as thence y'all tin recall tab2 past times using window.location.hash object. This volition render simply "tab2". You tin likewise 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 as well as JQuery code. We stimulate got pose the JQuery code inward $(document).ready(), thence it volition last executed when page volition last loaded.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JQuery as well as JavaScript lawsuit to acquire electrical flow URL alongside parameters </title>
</head>
<body>
<div id="choice">
<h2>JQuery Code for getting electrical flow URL as well as Hash </h2>
</div>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
//windo.location.pathname volition laissez passer on y'all path, afterwards 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 as well as hash value using JavaScript as well as jQuery. It's real easy, y'all simply ask to know well-nigh window.location Javascript object, but if y'all are jQuery fan, as well as desire to avoid cross browser hassles, as well as thence y'all tin likewise accept payoff 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 Together With Hash Tag Using Jquery Together With Javascript"
Post a Comment