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,147
  • 4
  • 29
  • 42

3 Answers3

3

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

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
1

Use this:

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

Definition of location.href

su-
  • 3,116
  • 3
  • 32
  • 42
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
  • 11,380
  • 19
  • 83
  • 138