Skip to content


Copy script tag list by slicing #189

merged 1 commit into from

1 participant


Same issue as #186 but for executeScriptTags. Didn't originally think this was necessary since the number of scripts on the page isn't directly changed by each iteration of the loop, but I ran into a scenario where it's indirectly changed:

   <div id="container">
   // another script

If there are multiple scripts on the page and any of them except the last one remove or overwrite themselves, executeScriptTags will throw an error.

@reed reed merged commit ab78418 into turbolinks:master
@reed reed deleted the reed:copy-script-tag-list branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2013
  1. @reed

    Copy script tag list by slicing

    reed committed
Showing with 2 additions and 1 deletion.
  1. +2 −1 lib/assets/javascripts/
3 lib/assets/javascripts/
@@ -85,7 +85,8 @@ changePage = (title, body, runScripts) ->
triggerEvent 'page:change'
executeScriptTags = ->
- for script in document.body.getElementsByTagName 'script' when script.type in ['', 'text/javascript']
+ scripts = document.body.getElementsByTagName 'script'
+ for script in scripts when script.type in ['', 'text/javascript']
copy = document.createElement 'script'
copy.setAttribute, attr.value for attr in script.attributes
copy.appendChild document.createTextNode script.innerHTML
Something went wrong with that request. Please try again.