URL encoding for document.location.href

Posted by Tyler on Stack Overflow See other posts from Stack Overflow or by Tyler
Published on 2010-05-04T16:26:50Z Indexed on 2010/05/12 19:44 UTC
Read the original article Hit count: 296

Filed under:
|
|

Hello -

I am building an iFrame and am using document.location.href -> my exact code is:

<script type="text/javascript">
document.write("<iframe src='http://www.facebook.com/plugins/like.php?href=" + document.location.href + "&layout=standard&show_faces=false&action=like&font=verdana&colorscheme=light' frameborder=0></iframe>");
</script>

This is working great for all of my pages except one. I believe the issue with the one page is caused by a dash "-" being in the page name. My questions is - is there a way to encode my src differently so that the link works? The CORRECT URL I want it to pull is:

[]/products/Product%252dExample.html

But what it IS pulling in is:

[]/products/Product-Example.html

And this is causing the page to not work correctly.

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about iframe