当前url javascript绑定到html

当前url javascript绑定到html,javascript,html,Javascript,Html,我正在尝试将我页面的当前url绑定到此html 如何才能做到这一点您可能希望尝试动态创建iframe: <html> <head> <script type="text/javascript"> function insertFbButton() { f = document.createElement("IFRAME"); f.setAttribute( "src", "http://www.facebook.

我正在尝试将我页面的当前url绑定到此html
如何才能做到这一点

您可能希望尝试动态创建iframe:

<html>
 <head>
  <script type="text/javascript">
   function insertFbButton() {
    f = document.createElement("IFRAME");
    f.setAttribute(
     "src",
     "http://www.facebook.com/plugins/like.php?"
     + window.location.href
     + "&amp;layout=button_count&amp;show_faces=true&amp;width=450"
     + "&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=21"
    );
    f.style.width = 450+"px";
    f.style.height = 210+"px";
    document.body.appendChild(f);
   }
  </script>
 </head>
 <body>
  <p>Content</p>
  <script>insertFbButton();</script>
  <p>Content</p>
 </body>
</html>

函数insertFbButton(){
f=document.createElement(“IFRAME”);
f、 集合属性(
“src”,
"http://www.facebook.com/plugins/like.php?"
+window.location.href
+“&;布局=按钮\u计数&;显示\u面=真值&;宽度=450”
+“&;action=like&;font=arial&;colorscheme=light&;height=21”
);
f、 style.width=450+“px”;
f、 style.height=210+“px”;
文件.正文.附件(f);
}
内容

insertFbButton(); 内容


如果不需要完整的url,请使用
window.location.href
window.location.pathname
表达式