javascript - Dynamic script not loading on history.go() -
i have static html page cannot edit- refer js file though, redirect url request on iis server js file- dynamically inject jquery can use it. here's code use insert jquery:
var script = document.createelement( 'script' ); script.src = 'http://code.jquery.com/jquery-1.9.1.js'; script.type = 'text/javascript'; script.onload = jqueryready; //most browsers script.onreadystatechange = function () { //ie if ( this.readystate == 'complete' ) { jqueryready(); } }; this works great except in 1 specific case- if call history.go() on page when browser ie , page being served internal web server. hitting f5 not reload page properly. have put cursor in address bar , hit enter load right.
edit: forgot mention obvious- have breakpoint in jqueryready() function- , never gets hit- problem lies...
it works fine ie in dev environment if serve page , fire history.go() (with button click). works chrome, haven't tested firefox.
so there alternative history.go() fire 'true' page reload hitting enter in address bar?
this huge page - 6000 lines of html (i didn't write it) , jquery , javascript being loaded in head- know supposed load js stuff @ end of page. maybe related? feels timing issue...
anyone have thoughts things check/try? or know what's going on?
okay found it... solution here
bottom line code using isn't correct, recommended approach dynamically insert script document , handle ready event:
var script = document.createelement( "script" ); script.src = "/reporter/scripts/jquery-1.9.1.min.js"; if ( script.addeventlistener ) { script.addeventlistener( "load", jqueryready, false ); } else if ( script.readystate ) { script.onreadystatechange = jqueryready; } document.getelementsbytagname( 'head' )[0].appendchild( script ); additionally, needed check if jquery loaded in jqueryready function:
function jqueryready() { // check if jquery exists if ( typeof jquery != 'undefined' ) { // stuff $(document).ready() } } this seemed work in cases find.
hope helps else!
Comments
Post a Comment