-3

I am creating a badge for my website.

UPDATE and CHANGE the question body

I'm trying to send the URL of the page that contain my badge back to my site when someone clicks the badge.

  • Maybe its just me, but I really don't understand the question. If you are asking how to find the URL of the current page, that question is answered here: http://stackoverflow.com/questions/1034621/get-current-url-with-javascript – Greg Mar 01 '11 at 03:02
  • @Greg I edited it to what I *think* the OP is asking. Please let me know if you think I am wrong. Cheers. – alex Mar 01 '11 at 03:04
  • @alex: sorry for my bad language. i think the question body is good ;). my title was wrong. and for the answer is the document.url is enough? –  Mar 01 '11 at 03:09
  • @alex, at this point it is anyone's guess :-). @raika, you really need to write a more clear explanation of what you're trying to achieve. What will the badge do? – Greg Mar 01 '11 at 03:09
  • @Raika If you want the current page URL, use `document.URL`. If you want the referrer, use `document.referrer`. – alex Mar 01 '11 at 03:10
  • @Greg : its something like [stack flair](http://stackoverflow.com/users/flair). but i want the source url that contain my badge. like www.thatdomain.com. and sorry for my bad question :| –  Mar 01 '11 at 03:12
  • @Raika, it isn't so much the language. It is that you are saying so little about what you are trying to achieve. Are you trying to send the URL of this page back to your own page when someone clicks the badge? I ask because you mention the querystring below. – Greg Mar 01 '11 at 03:17
  • 1
    @Greg : yes and i want to do it with querystring. is it wrong? and what should i do? –  Mar 01 '11 at 03:18
  • @Raika, it isn't reasonable to expect folks on here to pull the details out of you point by point. I suggest you write a detailed description of what you want to do in the question body. – Greg Mar 01 '11 at 03:34
  • @Greg : ok. but do me a favor and edit title yourself. thanks –  Mar 01 '11 at 03:39

2 Answers2

2

You can get the referrer with document.referrer, but bear in mind this may not be set. Proxies often send a different one or strip it, and I don't think you can check X_FORWARDED_FOR in JavaScript.

alex
  • 479,566
  • 201
  • 878
  • 984
0

Try this:

<script>
alert(document.URL);
</script>

Mozilla Dev Center is really good and complete -- a great resource. You can find it here.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
Chris Ladd
  • 2,795
  • 1
  • 29
  • 22
  • is it safe too add it to my querystring? –  Mar 01 '11 at 02:58
  • `Returns a string containing the URL of the current document.` Is that really what he wants? I admit the title is confusing... – alex Mar 01 '11 at 03:01
  • @alex : yours better so i change title :P –  Mar 01 '11 at 03:02
  • @Raika My edit overwrited yours 9 seconds later. Still, from the question body, it seems the referrer is really what the OP wants. – alex Mar 01 '11 at 03:04
  • @alex, I suppose you're right! Saw what I wanted to see... ;) @Raika, you should mark @alex's answer as correct. – Chris Ladd Mar 01 '11 at 16:23