From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../ru/web/api/window/hashchange_event/index.html | 159 +++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 files/ru/web/api/window/hashchange_event/index.html (limited to 'files/ru/web/api/window/hashchange_event') diff --git a/files/ru/web/api/window/hashchange_event/index.html b/files/ru/web/api/window/hashchange_event/index.html new file mode 100644 index 0000000000..84087f124c --- /dev/null +++ b/files/ru/web/api/window/hashchange_event/index.html @@ -0,0 +1,159 @@ +--- +title: hashchange +slug: Web/API/Window/hashchange_event +translation_of: Web/API/Window/hashchange_event +--- +

Событие hashchange генерируется когда изменяется идентификатор фрагмента URL (т.е. часть URL следующая за символом #, включая сам символ #).

+ +

Общая информация

+ +
+
Спецификация
+
HTML5
+
Интерфейс
+
HashChangeEvent
+
Bubbles
+
Yes
+
Cancelable
+
No
+
Target
+
defaultView
+
Действие по умолчанию
+
None
+
+ +

Свойства

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyTypeDescription
target {{readonlyInline}}{{domxref("EventTarget")}}The browsing context (window).
type {{readonlyInline}}{{domxref("DOMString")}}The type of event.
bubbles {{readonlyInline}}{{jsxref("Boolean")}}Whether the event normally bubbles or not.
cancelable {{readonlyInline}}{{jsxref("Boolean")}}Whether the event is cancellable or not.
oldURL {{readonlyInline}}{{jsxref("String")}}The previous URL from which the window was navigated.
newURL {{readonlyInline}}{{jsxref("String")}} 
+ +

Совместимость с браузерами

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support5.0{{ CompatGeckoDesktop("1.9.2") }}
+ Support for the oldURL/newURL attributes added in Firefox 6.
8.0
+ oldURL/newURL attributes are not supported.
10.65.0
+
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support2.2{{ CompatGeckoMobile("1.9.2") }}9.011.05.0
+
+ +


+ There are several fallback scripts listed on this page. Basically those scripts check the location.hash at a regular interval. Here is a version that allows only one handler to be bound to the window.onhashchange property:

+ +
(function(window) {
+
+  // exit if the browser implements that event
+  if ( "onhashchange" in window.document.body ) { return; }
+
+  var location = window.location,
+    oldURL = location.href,
+    oldHash = location.hash;
+
+  // check the location hash on a 100ms interval
+  setInterval(function() {
+    var newURL = location.href,
+      newHash = location.hash;
+
+    // if the hash has changed and a handler has been bound...
+    if ( newHash != oldHash && typeof window.onhashchange === "function" ) {
+      // execute the handler
+      window.onhashchange({
+        type: "hashchange",
+        oldURL: oldURL,
+        newURL: newURL
+      });
+
+      oldURL = newURL;
+      oldHash = newHash;
+    }
+  }, 100);
+
+})(window);
+
+ +

Похожие события

+ + -- cgit v1.2.3-54-g00ecf