javascript: cancel all kinds of requests

别说谁变了你拦得住时间么 提交于 2020-01-09 10:03:48

问题


My website makes a lot of requests. I often need to cancel all current requests, so that the browser is not blocking relevant new requests.

I have 3 kinds of requests:

  • Ajax
  • inserted script-tags (which do JSONP-Communication)
  • inserted image-tags (which cause the browser to request data from various servers)

For Ajax its no problem as the XMLHttpRequest object supports canceling. What I need is a way to make any browser stop loading resources, from DOM-Objects.

Looks like simply removing an object (eg. an image-tag) from the DOM only helps avoiding an request, if the request is not already running.

UPDATE: a way to cancel all requests, which are irrelevant, instead of really any request would be perfect.


回答1:


window.stop() should cancel any pending image or script requests.




回答2:


I think document.close() stops all requests, but I'm not so sure about it.



来源:https://stackoverflow.com/questions/117551/javascript-cancel-all-kinds-of-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!