diff --git a/jquery.pjax.js b/jquery.pjax.js index 5cec3f28..9d09cc8e 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -187,6 +187,12 @@ function pjax(options) { } var timeoutTimer + + if(typeof options.beforeSend === 'function'){ + if(!options.beforeSend()) { + return false; + } + }; options.beforeSend = function(xhr, settings) { // No timeout for non-GET requests @@ -281,6 +287,7 @@ function pjax(options) { state: pjax.state, previousState: previousState }) + executeScriptTags(container.scripts) context.html(container.contents) // FF bug: Won't autofocus fields that are inserted via JS. @@ -293,8 +300,6 @@ function pjax(options) { autofocusEl.focus(); } - executeScriptTags(container.scripts) - // Scroll to top by default if (typeof options.scrollTo === 'number') $(window).scrollTop(options.scrollTo) @@ -723,7 +728,12 @@ function executeScriptTags(scripts) { var script = document.createElement('script') script.type = $(this).attr('type') script.src = $(this).attr('src') - document.head.appendChild(script) + if(pjax.options.async) { + document.head.appendChild(script) + } + else { + $(document.body).append(script) + } }) }