Execute external script tags #88

merged 1 commit into from Nov 26, 2012

3 participants


Related to issue #87. When evaluating script tags, this handles those with a src attribute by copying the element, removing the original, and then inserting the copy into the DOM in the original's place, which triggers a load event on the script.

@davydotcom davydotcom commented on the diff Oct 19, 2012
@@ -71,7 +71,16 @@ changePage = (title, body) ->
triggerEvent 'page:change'
executeScriptTags = ->
- eval(script.innerHTML) for script in document.body.getElementsByTagName 'script' when script.type in ['', 'text/javascript']
+ for script in document.body.getElementsByTagName 'script' when script.type in ['', 'text/javascript']
+ if script.src? and not script.getAttribute('data-turbolinks-evaluated')?
+ copy = document.createElement 'script'
davydotcom Oct 19, 2012

not sure but can you use script.cloneNode() here ?

reed Oct 19, 2012

I tried that initially, but it wouldn't trigger the load event.

@dhh dhh merged commit 9ecff71 into turbolinks:master Nov 26, 2012

heh, was just about to write...good to merge, you beat me to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment