javascript - Instability when loading JQuery dynamically in Firefox -
No need to declare a function where the library Jyoki me depending on the situation and some other scripts, warning As a .js script which is a class of the same name, I tested that functionality in Google Chrome and Mozilla Firefox. Firstly the script is always loaded correctly before the implementation of class function / class warning (), even though the scripts in Firefox are loaded astatically. In other words, when the function warnings are executed, some time is not jQuery Are still ready, this page is needed to refresh.
To further clarify, the value given by the Firefox Error Console is:
ReferenceError: jQuery is not defined
Below Code:
if (typeof (warning) === 'undefined') {var scripts = [DIR_JS_LIB + 'lib / jQuery / jQuery. min.js ', DIR_JS_LIB +' lib / jQuery / jQuery-ui / jQuery-ui.min.js ', DIR_JS_LIB +' scripts / COMPONENTES / dialogues / AcaoJanela.js ', DIR_JS_LIB +' scripts / COMPONENTES / dialogues / Botao. JS ', DIAR_JS_LB +' Scripts / Components / Dialogs / Dialogs JS ', DIAR_JS_LB +' script / component / dialog / alert.js']; (Var i = 0; i & lt; scripts.length; i ++) {include (script [i]); }} Window.onload = function () {warning (window.mensagem, window.titulo, window.botoes); } Function (file_path) {var j = document.createElement ("script"); J.src = file_path; Document.getElementsByTagName ('head') [0] .appendChild (j); }
Assure a cross-browser solution to load and prepare dependent JS libraries Well known problem Your contains
script is not found well What works best for me is checking the status of loaded files, and chaining calls as callback Does. In your case it will look like the following:
functions include (file name, callback) {var fileref = document.createElement ('script'); Fileref.setAttribute ("Type", "Text / JavaScript"); Fileref.setAttribute ("src", file name); If (fileref.readyState) {fileref.onreadystatechange = function () {/ * IE * / if (fileref.readyState == "load" || fileref.readyState == "complete") {fileref.onreadystatechange = null; call back(); }}} {Fileref.onload = function () {/ * other browser * / callback (); }} // to try to find the head, otherwise document default if Element (typeof fileref! = "Undefined") (document.getElementsByTagName ( "head") [0] || document.documentElement) .appendChild (fileref) } if (typeof (warnings) === 'undefined') {var script = [DIR_JS_LIB + 'lib / jQuery / jquery.min.js', DIR_JS_LIB +' lib / jQuery / jQuery-ui / jQuery-ui.min. Js ', dir_js_lb +' scripts / components / dialogs / plans.js ', dir_js_lib +' script / component / dialog / boto. JS ', DIR_JS_LB +' script / component / dialog / dialog.js', DIRE_JS_LB + 'script / components / dialog / alert.js']; Includes (Script [0], function () {include script ([1], function () {include script ([2], function () {include (script [3], function () {} (includes scripts [4], function (() (script [5], function () {alert (window. Mensgem, Vindotitulo, Vindokbots);})}});})}}}}}); });}
Comments
Post a Comment