Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

location.href jquery

How to Get the Current Page URL with JQuery

Getting the Current page URL with JQuery is very much important, especially when redirecting or when tracking users’ activities.

There are two methods you can use to get the current page URL with jquery:

  1. Use $(location).attr(“href”)
  2. Use window.location.href

Use $(location).attr(“href”) to get the current page URL

You can use the location object and attr method to get the current page URL as shown in the example below.

$(function(){
var url = $(location).attr("href");
alert(url);
});

Use window.location.href to get the current page URL

You can also use the location and href objects to get the current page URL as shown in the example below



This post first appeared on WPBlogCafe, please read the originial post: here

Share the post

location.href jquery

×

Subscribe to Wpblogcafe

Get updates delivered right to your inbox!

Thank you for your subscription

×