-2

I have a code to get number of shares of particular url. The url value is equal to the value we type in a text box.

Jsfiddle

Part of the code

html

 <input type="text" class="form-control" id="urlInput" />

Jquery

$('#getJSON').click(function () {
    $('#data-tab').fadeOut();
    $URL = $('#urlInput').val();

    totalShares($URL);

    $('#data-tab').fadeIn();

});

So , here $URL is equal to the value of text box.I need to change it so that $url changes to the value of current address bar url

I am bit new to jquery.I tried searching a lot. I tried replacing it document.url and location.href but it still doesn;t work.

Any tips? thanks

Edit:

I know the terminologies of the code console.log(window.location.href); ,window.location.href. however, when i use in the code, they don't seem to work

Rahul Shah
  • 1,387
  • 4
  • 22
  • 41
  • Hi @scrowler, i have already been through that...i have tried that method as written in the 2nd last line of the question, but in vain :( – Rahul Shah Aug 07 '14 at 04:18
  • to get the URL use `document.URL` or `window.location.href`.\ – Mritunjay Aug 07 '14 at 04:18
  • Well `document.URL` will definitely get you the current URL. If it's not working, the actual URL could be something other than displayed in the browser URL bar. (Similar to how if you try to alert document.URL in a JSFiddle, the url's don't match exactly) – TrazeK Aug 07 '14 at 04:25
  • When you say "however, when i use in the code, they don't seem to work", can you explain what's not working exactly? – TrazeK Aug 07 '14 at 04:38

4 Answers4

1

This has got to have been answered already, but have you tried.. console.log(window.location.href);? var url = document.URL? This isn't PHP, variables tend not to start with $

sent1nel
  • 1,580
  • 1
  • 15
  • 31
0

The url for the page your script is running on can be accessed by document.URL

celeritas
  • 2,191
  • 1
  • 17
  • 28
0

To get Current Path:Use->

$(location).attr('href');

where location is an object.

You can get other properties of this objects from web browsers console window.

0

You don't need jQuery for this. In JavaScript, it's like this:

var url = document.location;
Nischaal Cooray
  • 210
  • 2
  • 12