I am getting into a problem with Twitter widget Timeline, but the issue is applicable to any script.
I want to embed Twitter widget Timeline (end result is an iframe). Seems like the way of adding the iframe is inserting a script in the post which will call another script with functions that will then execute a function to load/create the final iframe.
<script>
!function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
if (!d.getElementById(id)) {
js = d.createElement(s);
js.id = id;
js.src = p + "://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
}
}(document, "script", "twitter-wjs");
</script>
In my website I have posts (post1,post2,post3) which display partial content of the post. When a user clicks in the title of one of these, The partial post is dettached from the Dom, the full post is called with Ajax and attached into the Dom. Then when closing the full loaded post, its content is removed from the Dom and the partial post content is attached again. (this attaching dettaching is to prevent conflicts with #ids).
When my partial content is attached again into the post, the iframe is empty and the script will not execute again to load it. (even if I made a custom dumb script). This empty iframe happens only with Twitter widget, not with other iframes such as Youtube videos.
Could someone please guide me here?
Update:
Several things here. The script added in the post seems to load twitter widget script to the head. The post script checks if this head script exists before creating the iframe. This implies the iframe is not created in the full post (ajax) load. I can delete the head script and then the iframes gets created correctly in the full post.
But this "trick" doesnt work for the reattached content. The problem remains, when I attach the content back the post script doesn't run again (any script).
Update2:
A fiddle with the retach issue http://jsfiddle.net/KsFJR/