Browse Source

[add][监听]

zhangwei 2 years ago
parent
commit
0ba6996348
1 changed files with 31 additions and 1 deletions
  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)
+})