javascript - load js library from within a function? -
i have ever loaded in js library in head of html doc so
<head> <script src="somelink.js" /> </head>
my question is, can load script within function , if like?
function() { src="somelink.js" return somemethod.bla; }
would work? presumably not.
i have reasons wanting leave them out of question now.
is possible load in library within function , if like?
try :
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>load demo</title> <style> body { font-size: 12px; font-family: arial; } </style> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> </head> <body> <b>successful response (should blank):</b> <div id="success"></div> <b>error response:</b> <div id="error"></div> <script> $( "#success" ).load( "somelink.js", function( response, status, xhr ) { if ( status == "error" ) { var msg = "sorry there error: "; $( "#error" ).html( msg + xhr.status + " " + xhr.statustext ); } }); </script> </body> </html>
Comments
Post a Comment