javascript - 我可以在 windows.location 中捕获服务器返回 false 吗?

标签 javascript

如果我写 windows.location="/start/open"; 并从服务器端返回 false 我会得到空白页面。
我能捕获这个吗?

最佳答案

没有

windows.location=some URL is just like normal request

但您可以使用 HTTP referer(不要拼写错误)并将客户端重定向回之前所在的页面

例如。在 PHP 中

header('Location: ' . $_SERVER['HTTP_REFERER']);

在 ASP.NET 中

Response.Redirect("Location: " +Request.ServerVariables.Get("HTTP_REFERER"));

Java Servlet

response.setHeader("Location: "+ request.getHeader("HTTP_REFERER"));  

关于javascript - 我可以在 windows.location 中捕获服务器返回 false 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38246218/

相关文章:

javascript - 如何使用VueJS阻止组件上的点击事件冒泡?

javascript - 访问 html 中的资源(图像等)

javascript - 如何更改幻灯片更改时图像的 href

javascript - 谷歌街景: Show markers within given radius

javascript - 如何让 Highcharts Sparkline 显示在我的页面上。

javascript - 在 webpack 中导入 jQuery 插件

javascript - 确定网络应用程序的筛选时间

javascript - 出现在一个元素之后的所有元素的选择器

javascript - 当设置一个 svg 显示 : none, 时,其他 SVG 元素变为黑色

粘贴时javascript onkeypress限制字符