Bladeren bron

[add][监听]

zhangwei 2 jaren geleden
bovenliggende
commit
0ba6996348
1 gewijzigde bestanden met toevoegingen van 31 en 1 verwijderingen
  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)
+})