Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Dynamically load a Gist embed?

Tags:

jquery

gist

I'm not sure where to look for this. I'm looking to create a drop down to select a Gist ID and then generate it (embed) in a placeholder div.

I previously had the scripts generated, but hidden, and simply showed them by rel ID. But this is extremely slow with even more than three Gist embeds.

I've tried getScript, but I guess the document.write in the Gist embed code just doesn't let it slide.

Can someone point me in the right direction?

like image 843
Brooklyn Nicholson Avatar asked Dec 09 '22 02:12

Brooklyn Nicholson


1 Answers

The problem here is that document.write used by the Gist embed JavaScript is not executed after page load. To get around this, create an iframe, set its body to the Gist embed JS, and set an onload event to tell the parent to resize the iframe accordingly. Here is my solution: https://gist.github.com/1748966

like image 134
JeremiahLee Avatar answered Jan 01 '23 06:01

JeremiahLee