2011-04-05 49 views
0

以下是我正在使用的URL我想要使用放置此代碼的網頁的URL來更改href標記,我可以使用「window.location.href」但我想要連接它在href標記的位置的URL,我使用asp.net將javascript連接到網址

<iframe src="http://www.XYZ.com/plugins/like.php?href=<?php echo rawurlencode(get_permalink()); ?>&amp;layout=standard&amp;show_faces=true&amp;width=550&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:550px; height:80px;" allowTransparency="true"></iframe> 

我要取代這個href=<?php echo rawurlencode(get_permalink()); ?>與當前頁面的網址,我怎麼能做到這一點,請讓我知道?

+2

您正在使用ASP.NET,但仍有PHP標記編碼。這是什麼? – 2011-04-05 10:08:05

+0

基本上,這是一個臉書的PHP插件,XYZ url是我要添加我的asp.net頁面鏈接的地方,這個按鈕將放置在哪裏。 – NoviceToDotNet 2011-04-05 10:09:51

回答

1

如果我理解你的問題正確,你應該能夠取代href=<?php echo rawurlencode(get_permalink()); ?>

href=<%= Request.Url.AbsoluteUri %> 

雖然防範XSS,你可以做很多事情不如下載AntiXss library並確保你編碼你輸出的URL:

href=<%= AntiXss.HtmlAttributeEncode(Request.Url.AbsoluteUri) %>  
2
<script type="text/javascript"> 
    // set the param 
    var href="<?php echo rawurlencode(get_permalink()); ?>"; 
    // get current location 
    var current_location = window.location.href; 
    // set the source of the iframe 
    document.getElementsByTagName('iframe')[0].src = current_location + '&href=' + href; 
</script> 
+0

你的解決方案也很棒。 – NoviceToDotNet 2011-04-05 12:42:04