{"id":668,"date":"2012-05-30T05:05:54","date_gmt":"2012-05-30T05:05:54","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=668"},"modified":"2012-05-30T05:05:54","modified_gmt":"2012-05-30T05:05:54","slug":"jquery-get-current-url-2-ways-to-get-current-url-using-jquery","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-get-current-url-2-ways-to-get-current-url-using-jquery\/","title":{"rendered":"jQuery Get Current URL Examples (2 Ways)"},"content":{"rendered":"<p>Here is a little trick to <em><strong>get current url of a web page using jQuery<\/strong><\/em>.<!--more--><\/p>\n<h2>How to Get Current URL using jQuery<\/h2>\n<p>You can do this in 2 ways using jQuery.<\/p>\n<p><strong>Method 1:\u00a0Pure jQuery style<\/strong><\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;script type=\"text\/javascript\"&gt;\n$(document).ready(function() {\nvar currentUrl = $(location).attr('href');\nalert (currentUrl);\n});\n&lt;\/script&gt;<\/pre>\n<p><strong>Method 2:\u00a0Mix of jQuery and native JavaScript<\/strong><\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;script type=\"text\/javascript\"&gt;\n$(document).ready(function() {\nvar currentUrl= window.location.pathname;\nalert (currentUrl);\n});\n&lt;\/script&gt;<\/pre>\n<p>That&#8217;s it for now!<\/p>\n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to to <em><strong>get current URL using jQuery<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a little trick to get current url of a web page using jQuery.<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[41],"class_list":["post-668","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-aM","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=668"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/668\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}