YaoRaoLov 2009-02-02 12:54 采纳率: 50%
浏览 372
已采纳

如何转到另一个网页?

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

  • 写回答

28条回答 默认 最新

  • 狐狸.fox 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";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(27条)

报告相同问题?

悬赏问题

  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计