0

Possible Duplicate:
Request Address in Javascript

I am using a Facebook plugin in my web page, as shown:

<iframe 
   src="http://www.facebook.com/plugins/like.php?href=YOUR_URL"
   scrolling="no" 
   frameborder="0"
   style="border:none; width:120px; height:30px">
</iframe>

How can I get the current URL of the web page, using JavaScript? I need to assign current URL instead of href=YOUR_URL. How can I achieve this?

Community
  • 1
  • 1
selva_pollachi
  • 4,117
  • 4
  • 27
  • 41

3 Answers3

3

Just don't put an href parameter. Facebook will default to the current page.

Niet the Dark Absol
  • 311,322
  • 76
  • 447
  • 566
1

Use this:

window.location.href (or simply location.href)

Definition of location.href

su-
  • 3,085
  • 3
  • 29
  • 41
0

jQuery is your friend here:

var original = $("iframe").attr('src');
var url = window.location;
$("iframe").attr('src', original + url);​

HTML

<iframe src="http://www.facebook.com/plugins/like.php?href="></iframe>​

http://jsfiddle.net/charlescarver/2JEay/

Charlie
  • 10,718
  • 17
  • 78
  • 137