Why can I do this:
$("button").on('click', function(){window.history.back();});
however, when I try;
$("button").on('click', window.history.back); /*or*/ $("button").on('click', history.back);
I get:
Uncaught TypeError: illegal callin HTMLAnchorElement.dispatch (jquery-1.12.4.js: 5226)in HTMLAnchorElement.elemData.handle (jquery-1.12.4.js: 4878)
I got the impression that when there is no saved context, it defaults to the window object, which will allow me to do this?
First of all, it history.back()should be called using historyas a context, if it is equal by default window, it will throw the error you described. The problem here is that jQuery calls a handler with an element that has an event binding.
history.back()
history
window
, , . , jQuery , , history.back() .
history.back():
... window.history.back(); ...
back() history, , back this history.
back()
back
this
back:
... window.history.back ...
jQuery .on().
.on()
jQuery click, this . jQuery this DOM, .
click
, back() this, , history, .
, , , , , .
The attribute history windowsimply refers to the History interface and can only be called globally.
The failure method uses the context of an element that does not have an attribute history.
Source: https://habr.com/ru/post/1687986/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1687981/in-reactivex-how-do-i-pass-other-parameters-to-observercreate&usg=ALkJrhiQOlxrEPWnsYEWPEhMJaj0Na0MTgPrecondition Matrix Solver - pythonPython does not sum (add) numbers, just sticking them together - pythonBinary Tree in Python Number of Nodes in Range - pythonWhy does the ShEx constant not match the same term in the data? - semantic-webGetting "Internal error: Scala instance does not exist or is invalid" when trying to start a worksheet in IntelliJ IDEA - scalaiPhone X Aligning the bottom of an object in the ruins of Safe Area on other devices - iosWhy does GCC say that a variable is not used when it is not? - cThe audio file captured by MediaRecorder is damaged after it is sent to the server using Retrofit 2 - androidWhat makes Eclipse Oxygen 1a throw a new JavaModelException? - javaAll Articles