Jerry Jerry - 2 months ago 9
jQuery Question

Jquery not working on IE 10

I have some code

<script type="text/javascript">
$(document)
.ready(function() {
var count = 0;
window.onload = function () {
if (typeof history.pushState === "function") {
history.pushState("back", null, null);
window.onpopstate = function () {
history.pushState('back', null, null);
if (count == 1) { window.location = '/Test/OK'; }
};
}
}
setTimeout(function () { count = 1; }, 200);
});




I just want to call one URL if press back on browser

It is only working on Chrome and Firefox not working on IE10

Thanks

Answer

Your problem is that $(document).ready(function() { ... }); IS the jQuery way of doing a window.onload

What you're doing is telling jquery to onload set an onload event.

Remove window.onload = function () { and its matching closing brace and you should be good to go. Also you will no longer need the setTimeout which seems like a hack to make the double onload work.