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。
  • 相关阅读:
    创建一个简单的图片服务器
    spring-boot系列:初试spring-boot
    java的动态代理机制
    jedis连接池详解(Redis)
    使用logback.xml配置来实现日志文件输出
    redis在mac上的安装
    理解RESTful架构
    分布式应用框架Akka快速入门
    [Java基础]Java通配符
    Mac vim iterm2配色方案
  • 原文地址:https://www.cnblogs.com/qhorse/p/4898268.html
Copyright © 2011-2022 走看看