zoukankan      html  css  js  c++  java
  • window.location.href和window.location.replace的区别

    有3个html页面(1.html, 2.html, 3.html)。
    
    进系统默认的是1.html ,当我进入2.html的时候, 
    2.html里面用window.location.replace("3.html");与用window.location.href("3.html");
    从用户界面来看是没有什么区别的, 但是当3.html页面有一个“返回”按钮,调用window.history.go(
    -1);wondow.history.back();
    方法的时候,一点这个返回按钮就要返回2.html页面的话,区别就出来了, 当用window.location.replace(
    "3.html");连到3.html页面的话, 3.html页面中的调用window.history.go(-1);wondow.history.back();方法是不好用的,会返回到1.html 。 当用window.location.href("3.html");连到3.html页面的话, 3.html页面中的调用window.history.go(-1);wondow.history.back();方法是好用的,会返回2.html。 因为window.location.replace("3.html");是不向服务器发送请求的跳转, 而window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的, 所以会跳到系统默认页面1.html 。window.location.href("3.html");是向服务器发送请求的跳转,window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的, 所以就可以返回到2.html。
  • 相关阅读:
    sql 生成随机数 以及不重复随机数
    值提供器 AND 模型绑定器
    web项目在iis配置好后不能正确访问问题集锦,以及IIS常规设置
    js
    性能优化
    MVC3;0问题与知识点
    EntityFramework
    MSSQL2008 临时总结文档2014
    py--使用__slots__
    py--使用@property
  • 原文地址:https://www.cnblogs.com/qhorse/p/4898268.html
Copyright © 2011-2022 走看看