-4

Some of the queries we have can take tens of seconds to complete. I would like to be able to cancel the page-load as if the "Stop" button from browser was pressed.

But binding it to key shortcuts using javascript.

From extensive testing it seems that window.stop() works only when the document is not ready or still loading. I would like to stop the page from loading after a link was clicked.

The goal of doing it using javascript is that I would like to perform other operations too.

Tested in Chrome, FF dev and IE...

Anyone encountered a similar behavior and have suggestions on how to proceed ?

1- user clicks a link/a/href

2- realizes its the wrong link

3- presses ctrl-c to stop the loading and stay on this page

the function checks for certain conditions before proceeding to not prevent default behavior...

TLDR: when calling window.close() after click a link/a it wont stop the page from loading, is there any other way to stop a page from loading after a href click event

hexYeah
  • 1,040
  • 2
  • 14
  • 24
  • You haven't asked a question here. If you want help changing your logic we need to see your code. – Rory McCrossan Nov 22 '17 at 16:12
  • How are you running your "queries"? Are you redirecting to a new page (as implied by "page-load" in your question)? In which case "esc" works fine. Are you using ajax? If so, see here: https://stackoverflow.com/a/4551178/2181514 – freedomn-m Nov 22 '17 at 16:16
  • key bindings bound to the stop button? Maybe just bind to whatever code you are calling that is cancelling your request? – epascarello Nov 22 '17 at 16:18
  • for some reason window.stop() does not stop the loading after was clicked – hexYeah Nov 22 '17 at 16:21
  • its sad to see ppl down-voting your question this fast... I really looked around before posting, now I lost the little rep I had and wont be able to upvote their answers in a loooong time... – hexYeah Nov 22 '17 at 16:28
  • Because is bad questioned. The people here will help with your work, but you can't ask a "how to do this?" and wait us to reply. You must share your code and tests, and maybe by testing you find an answer and don't even need to write the question. – Jorge Fuentes González Nov 22 '17 at 16:30
  • Check: https://stackoverflow.com/help/how-to-ask – Jorge Fuentes González Nov 22 '17 at 16:30
  • Maybe you should change the other page that takes so long to load. Can you offload it to an Ajax request which can be aborted? – epascarello Nov 22 '17 at 16:39
  • From the edit (after most of the downvotes...) it looks like you want to cancel the server-side processing because the user has navigated away - is that correct? This is a very different question from way the original was worded. You might like to specify what server-side tech you are using (.Net/Node/php etc). – freedomn-m Nov 22 '17 at 16:52
  • yea, well... I dont really mind the server side part :P I wish to stop the href loading as if the user press the stop button in the browser... Its harder then i thought... Wish I know more programmers ... – hexYeah Nov 22 '17 at 18:31

1 Answers1

0

It turns out that you cannot use this method the way I needed too.

The stop() method is exactly equivalent to clicking the stop button in the browser. Because of the order in which scripts are loaded, the stop() method cannot stop the document in which it is contained from loading, but it will stop the loading of large images, new windows, and other objects whose loading is deferred. source / developer.mozilla.org

hexYeah
  • 1,040
  • 2
  • 14
  • 24