Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

includeFunc.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. function include(filename, afterfunc) {
  2. include.seq = (include.seq)? include.seq + 1: 1;
  3. var id = new Date().getTime() + "-" + include.seq;
  4. var inc = document.createElement("iframe");
  5. inc.id = "inc-" + id;
  6. inc.src = filename;
  7. inc.style.display = "none";
  8. document.write("<span id=\"" + id + "\"></span>");
  9. var incfunc = function() {
  10. var s = (function() {
  11. var suffix = (n = filename.lastIndexOf(".")) >= 0 ? filename.substring(n): "default";
  12. if (suffix == ".html") return inc.contentWindow.document.body.innerHTML;
  13. if (suffix == ".txt") return inc.contentWindow.document.body.firstChild.innerHTML;
  14. if (suffix == "default") return inc.contentWindow.document.body.innerHTML;
  15. })();
  16. var span = document.getElementById(id);
  17. var insertBeforeHTML = function(htmlStr, refNode) {
  18. if (document.createRange) {
  19. var range = document.createRange();
  20. range.setStartBefore(refNode);
  21. refNode.parentNode.insertBefore(range.createContextualFragment(htmlStr), refNode);
  22. } else {
  23. refNode.insertAdjacentHTML('BeforeBegin', htmlStr);
  24. }
  25. };
  26. insertBeforeHTML(s.split("&gt;").join(">").split("&lt;").join("<"), span);
  27. document.body.removeChild(inc);
  28. span.parentNode.removeChild(span);
  29. if (afterfunc) afterfunc();
  30. };
  31. if (window.attachEvent) {
  32. window.attachEvent('onload',
  33. function() {
  34. document.body.appendChild(inc);
  35. inc.onreadystatechange = function() { if (this.readyState == "complete") incfunc(); };
  36. });
  37. }
  38. else {
  39. document.body.appendChild(inc);
  40. inc.onload = incfunc;
  41. }
  42. }