index.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
  7. <link rel="shortcut icon" href="<%= BASE_URL %>favicon.ico">
  8. <title>
  9. <%= VUE_APP_TITLE %>
  10. </title>
  11. </head>
  12. <body>
  13. <noscript>
  14. <strong>
  15. 请开启 JavaScript 功能来使用 <%= VUE_APP_TITLE %>。
  16. </strong>
  17. </noscript>
  18. <iframe id='IEIframe' style='display: none;' width="100%" height="100%" src="/static/ie.html"
  19. frameborder="0"></iframe>
  20. <div id="app">
  21. </div>
  22. </body>
  23. <script>
  24. var $tar = document.querySelector('title')
  25. var MutationObserver = window.MutationObserver ||window.webkitMutationObserver ||window.MozMutationObserver;
  26. var mutationObserver = new MutationObserver((mutations) => {
  27. console.log(mutations,'标题变动')
  28. })
  29. mutationObserver.observe($tar, {
  30. childList: true, // 子节点的变动(新增、删除或者更改)
  31. attributes: true, // 属性的变动
  32. characterData: true, // 节点内容或节点文本的变动
  33. subtree: true, // 是否将观察器应用于该节点的所有后代节点
  34. attributeFilter: ['class', 'style'], // 观察特定属性
  35. attributeOldValue: true, // 观察 attributes 变动时,是否需要记录变动前的属性值
  36. characterDataOldValue: true // 观察 characterData 变动,是否需要记录变动前的值
  37. })
  38. function IEVersion() {
  39. var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
  40. var isIE =
  41. userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
  42. if (isIE) {
  43. return true;
  44. } else {
  45. return false; //不是ie浏览器
  46. }
  47. }
  48. /* 如果是ie浏览器 */
  49. if (IEVersion()) {
  50. document.querySelector('#IEIframe').style.display = 'block'
  51. document.querySelector('#app').style.display = 'none'
  52. }
  53. // dataset 方法兼容 IE 浏览器。ie10及以下不支持dataset
  54. if (window.HTMLElement) {
  55. if (Object.getOwnPropertyNames(HTMLElement.prototype).indexOf('dataset') === -1) {
  56. Object.defineProperty(HTMLElement.prototype, 'dataset', {
  57. get: function() {
  58. var attributes = this.attributes // 获取节点的所有属性
  59. var name = []
  60. var value = [] // 定义两个数组保存属性名和属性值
  61. var obj = {} // 定义一个空对象
  62. for (var i = 0; i < attributes.length; i++) { // 遍历节点的所有属性
  63. if (attributes[i].nodeName.slice(0, 5) === 'data-') { // 如果属性名的前面5个字符符合"data-"
  64. // 取出属性名的"data-"的后面的字符串放入name数组中
  65. name.push(attributes[i].nodeName.slice(5));
  66. // 取出对应的属性值放入value数组中
  67. value.push(attributes[i].nodeValue);
  68. }
  69. }
  70. for (var j = 0; j < name.length; j++) { // 遍历name和value数组
  71. obj[name[j]] = value[j]; // 将属性名和属性值保存到obj中
  72. }
  73. return obj // 返回对象
  74. }
  75. })
  76. }
  77. }
  78. </script>
  79. </html>