Skip to content

Loading…

Copy script tag list by slicing #189

Merged
merged 1 commit into from

1 participant

@reed

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:

<body>
   <div id="container">
      <script>
      $('#container').html("content");
      </script>
   </div>
   <script>
   // another script
   </script>
</body>

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/turbolinks.js.coffee
View
3 lib/assets/javascripts/turbolinks.js.coffee
@@ -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 = Array::slice.call document.body.getElementsByTagName 'script'
+ for script in scripts when script.type in ['', 'text/javascript']
copy = document.createElement 'script'
copy.setAttribute attr.name, attr.value for attr in script.attributes
copy.appendChild document.createTextNode script.innerHTML
Something went wrong with that request. Please try again.