larry*wei 2009-02-02 12:54 采纳率: 0%
浏览 917
已采纳

如何重定向到另一个网页?

How can I redirect the user from one page to another using jQuery or pure JavaScript?

转载于:https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage

  • 写回答

30条回答 默认 最新

  • derek5. 2009-02-03 04:24
    关注

    One does not simply redirect using jQuery

    jQuery is not necessary, and window.location.replace(...) will best simulate an HTTP redirect.

    window.location.replace(...) is better than using window.location.href, because replace() does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco.

    If you want to simulate someone clicking on a link, use location.href

    If you want to simulate an HTTP redirect, use location.replace

    For example:

    // similar behavior as an HTTP redirect
    window.location.replace("http://stackoverflow.com");
    
    // similar behavior as clicking on a link
    window.location.href = "http://stackoverflow.com";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(29条)

报告相同问题?

悬赏问题

  • ¥20 5037端口被adb自己占了
  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误