diff --git a/README.md b/README.md index 58094e14..65d3bfb7 100644 --- a/README.md +++ b/README.md @@ -418,6 +418,14 @@ $(document).on('click', 'a[data-pjax]', function(event) { **NOTE** The new api gives you control over the delegated element container. `$.fn.live` always bound to `document`. This is what you still want to do most of the time. +### Script tags + +All script tags with attribute `src` will be move to head, for the reason once CSP enabled, internal `eval` will be disabled. If you don't want the script tags moved, add an attribute context with value `inline`: + +``` html + +``` + ## Contributing ``` diff --git a/jquery.pjax.js b/jquery.pjax.js index 444891e3..49ff2e9a 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -290,6 +290,8 @@ function pjax(options) { } catch (e) { } if (container.title) document.title = container.title + + executeScriptTags(container.scripts) fire('pjax:beforeReplace', [container.contents, options], { state: pjax.state, @@ -307,8 +309,6 @@ function pjax(options) { autofocusEl.focus(); } - executeScriptTags(container.scripts) - // Scroll to top by default if (typeof options.scrollTo === 'number') $(window).scrollTop(options.scrollTo) @@ -714,7 +714,7 @@ function extractContainer(data, xhr, options) { obj.contents.find('title').remove() // Gather all script[src] elements - obj.scripts = findAll(obj.contents, 'script[src]').remove() + obj.scripts = findAll(obj.contents, 'script[src][context!=inline]').remove() obj.contents = obj.contents.not(obj.scripts) }