重定向页面并防止页面的其余部分加载和脚本执行

问题描述:

我需要在开始加载时重定向页面(例如加载页面的头部),并且一旦重定向,就会阻止/停止页面内容的其余部分加载以及执行的其余脚本。

I need to redirect page when it starts loading (e.g. the head part of the page loaded) and once it is redirected prevent/stop the rest of the page content from loading and the rest of the script from execution.

如果我在打开HEAD标签并将页面重定向到另一个页面后的第一行放置此代码(window.location =/ other-page-url;),它是否会停止执行下一个脚本?
我想确定如果有,比方说,在第二行调用一些计数器脚本,在重定向之后,它将不会执行。

If I place this code (window.location = "/other-page-url";) at the first line after opening HEAD tag and redirect page to another one, will it stop execution of next going scripts? I want to be sure that if there are, let's say, some counter script called on the second line, just after redirection, it will not execute.

可能是JavaScript有一些停止页面加载/渲染的方法吗?

May be JavaScript has some method which stops page loading/rendering?

将用户重定向到另一个页面后,当前页面将立即停止执行。

Once you have redirected the user to a different page, the current page will stop execution immediately.