Posted By

liuran on 10/21/08


Tagged

import


Versions (?)

import the other file in javascript


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.