javascript - 使用 window.location 重定向不起作用

标签 javascript redirect window.location

我搜索了相关帖子,但所有尝试均无效。

我的问题是,我正在尝试使用 path+querystring 在 Javascript 中进行简单的重定向。我的代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Page1.aspx.cs" Inherits="WebApplication1.Page1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="submit" value="pesq" onclick="Redirect();"/>
    </div>
    </form>
    <script>
        function Redirect()
        {
          window.location.href = 'http://localhost:61267/Page1.aspx?q=name';            
        }
    </script>
</body>
</html>

window.location.href 始终设置为 'http://localhost:61267/Page1.aspx'

我尝试过使用 window.location.search 但仍然没有成功。

我做错了什么?

最佳答案

改用 document.location。

      document.location = 'http://localhost:61267/Page1.aspx?q=name';  

关于javascript - 使用 window.location 重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27725127/

相关文章:

javascript - 等待 url 在点击事件上发生变化

javascript - onclick 不是调用函数

javascript - 如何使用 GET 发送正文请求

asp.net-mvc - ASP.Net MVC 将特定路由重定向到外部站点

index.php 的 .htaccess 重定向打破了 404 页面

windows-7 - windows.location.href 使用 vbscript 在 IE10 上抛出错误

jquery - setTimeout 与 window.location 和 $(this)

javascript - mongodb 模式中具有不同对象类型的数组

javascript - 在javascript中加密文件(Phonegap应用程序)

每个页面上的 PHP 函数导致重定向循环