window.history.go()和history.back()以及location.reload()的用法以及不同


  
  
    
    
    
    
  1. window.history.go( -1);   返回上一页, 原页面表单中的内容会丢失;
  2. window.history.back( -1);  返回上一页, 原页面表单中的内容会保留.

以下为举例:


  
  
    
    
    
    
  1. <input type="button" value="刷新" οnclick="window.location.reload()">
  2. <input type="button" value="前进" οnclick="window.history.go(1)">
  3. <input type="button" value="后退" οnclick="window.history.go(-1)">
  4. <input type="button" value="前进" οnclick="window.history.forward()">
  5. <input type="button" value="后退" οnclick="window.history.back()">
  6. <input type="button" value="后退+刷新" οnclick="window.history.go(-1);window.location.reload()">

关于刷新:  


  
  
    
    
    
    
  1. window.history.go( 0); 是直接读取缓存数据,不会从服务器端获取数据;
  2. window.location.reload( true); 不管有没有缓存,都会强制刷新;
  3. window.location.reload( false); 有缓存就走缓存,没缓存就强制刷新;

你可能感兴趣的:(JS)