import the other file in javascript


/ Published in: JavaScript
Save to your folder(s)

Import the other script file. like the java or C++ .


Copy this code and paste it in your HTML
  1. ******************************************************
  2. // useage: $import('../include/mian.js', 'js'); default is common.js
  3. // $import('../style/style.css', 'css');
  4. //******************************************************
  5.  
  6. function $import(path, type){
  7. var i,
  8. base,
  9. src = "common.js",
  10. scripts = document.getElementsByTagName("script");
  11.  
  12. for (i = 0; i < scripts.length; i++) {
  13. if (scripts[i].src.match(src)) {
  14. base = scripts[i].src.replace(src, "");
  15. break;
  16. }
  17. }
  18.  
  19. if (type == "css") {
  20. document.write("<" + "link href=\"" + base + path + "\" rel=\"stylesheet\" type=\"text/css\"></" + "link>");
  21. } else {
  22. document.write("<" + "script src=\"" + base + path + "\"></" + "script>");
  23. }
  24. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.