Navigation
How to do it...
- Create a Chunk to include the following code.
<iframe id=”facebook_like_btn” src="http://www.facebook.com/widgets/like.php?href=http://mysite.com"
scrolling="no" frameborder="0"
style="border:none; width:450px; height:80px"></iframe>
- Write a script to update this value to reflect the current page location. Include this script with the Chunk code above.
Function dynShareLink() {
var url = window.location.hostname;
var newUrl = 'http://' + url;
var btn = document.getElementById('facebook_like_btn');
var str = btn.getAttribute('src');
var old = str.split('=')[1];
var newStr = str.replace(old,newUrl);
btn.setAttribute('href',newStr); };
- Create a new Plugin in the Manager. Go to the System Events tab and select OnWebPagePrerender. For the Plugin, include the following code.
<?php echo ‘<script>dynShareLink()</script>’ ;
How it works...
The short script will update the appended value in the src attribute of the iframe element. The plugin will call this function before the page renders, updating the value of the src attribute. This will tell the browser to update the code, and share the current page on facebook.