javascript - Switch .js file in multiple html pages -
i have multiple html pages dashboard.html, page1.html, page2.html, page3.html
etc... , 2 .js files, namely example1.js
, example2.js
file
**
from below example (
dashboard.html
) file, if click on load file 1 link, page , other html pages(page1.html, page2.html etc...) should replacedefault.js
fileexample1.js
file in remaining html pages until come dashboard page , change other.
**
i fine using external libraries
please check example code below same...
ps: newbie script, please me out
dashboard.html
<html> <head> <title>switch js file</title> <script src="jquery.min.js"></script> <script src="default.js"></script> </head> <body> <a href="javascript:;" id="loadexample1">load file 1</a> | <a href="javascript:;" id="loadexample2">load file 2</a> <h1>default js file loaded successfully!</h1> <a href="page1.html">go page 1</a> <a href="page2.html">go page 2</a> </body> </html>
page1.html, page2.html...
<!doctype html> <html> <head> <title>switch js file</title> <script src="jquery.min.js"></script> <script src="default.js"></script> </head> <body> <h1>default js file loaded successfully!</h1> </body> </html>
example1.js
$('h1').html('example1.js file loaded successfully!');
example2.js
$('h1').html('example2.js file loaded successfully!');
you can use jquery's getscript function, asynchronously retrieve desired javascript file page:
$("somebutton").click(function(){ $.getscript("somescriptfile.js"); });
Comments
Post a Comment