浏览代码

[add][监听]

zhangwei 2 年之前
父节点
当前提交
0ba6996348
共有 1 个文件被更改,包括 31 次插入1 次删除
  1. 31 1
      src/entry/content_iframe.js

+ 31 - 1
src/entry/content_iframe.js

@@ -1 +1,31 @@
-console.log('content_iframe', window.location)
+console.log('content_iframe', window.location)
+
+const _historyWrap = function (type) {
+    const orig = history[type];
+    const e = new Event(type);
+    return function () {
+        const rv = orig.apply(this, arguments);
+        e.arguments = arguments
+        window.dispatchEvent(e)
+        return rv
+    }
+}
+history.pushState = _historyWrap('pushState')
+history.replaceState = _historyWrap('replaceState')
+
+
+window.addEventListener('hashchange', function (event) {
+    console.log('hashchange', event)
+})
+
+window.addEventListener('popstate', function (event) {
+    console.log('popstate', event)
+})
+
+window.addEventListener('pushState', function (e) {
+    console.log('change pushState', e)
+})
+
+window.addEventListener('replaceState', function (e) {
+    console.log('change replaceState', e)
+})