concatenate javascript to URL
Following is the URL I am having I want to change the href tag with开发者_如何学运维 the URL of the page where this code is placed, that I can get using "window.location.href" but I want to concatenate it to URL at the place of href tag, I am using asp.net
<iframe src="http://www.XYZ.com/plugins/like.php?href=<?php echo rawurlencode(get_permalink()); ?>&layout=standard&show_faces=true&width=550&action=like&font=segoe+ui&colorscheme=light&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:550px; height:80px;" allowTransparency="true"></iframe>
I want to replace this href=<?php echo rawurlencode(get_permalink()); ?>
with the current page's url, how can I achieve this please let me know?
<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>
If I've understood your question properly, you should be able to replace href=<?php echo rawurlencode(get_permalink()); ?>
with:
href=<%= Request.Url.AbsoluteUri %>
Although to guard against XSS you could do a lot worse than download the AntiXss library and make sure you encode the URL you're outputting:
href=<%= AntiXss.HtmlAttributeEncode(Request.Url.AbsoluteUri) %>
精彩评论