I have the following iframe control (intended as a facebook button):
<iframe id="likeButton"
src="http://www.facebook.com/plugins/like.php?href="
scrolling="no"
frameborder="0"
style="border:none; overflow:hidden;
width:450px; height:80px;"
onprerender="setupLink()"
</iframe>
I have a javascript function defined above:
<script type="text/javascript">
function setupLink()
{
var iframe = $("#likeButton");
var newSrc = iframe.attr("src");
newSrc += encodeURIComponent(location.href) + lblKey.Text;
iframe.attr("src", newSrc);
};
</script>
lblKey is a label on an ASP.NET page that refers to a specific section of the page. However, as far as I can determine, this function is not called (if I put a warning (), then it does not bring anything in the beginning). I am new to javascript, but looking back at some articles on the Internet, I will point out that this should update the src property on the iframe.
EDIT:
I also tried the following:
<script type="text/javascript" >
$(function() {
var iframe = $("#likeButton");
var newSrc = iframe.attr("src");
newSrc += encodeURIComponent(location.href) + '<%= lblKey.Text %>';
iframe.attr("src", newSrc);
});
</script>
What doesn't work but doesn't:
<script type="text/javascript" >
$(function() {
alert('Hello');
});
</script>
source
share