前端获取当前路径

    1. //获取当前窗口的Url    
    2. //returnUrl=http://localhost:8080/shopping/buyCart.shtml?skuId=510&amount=1  
    3.     window.location.href      
    4. //获取当前窗口的主机名 例如:http://localhost:8080       
    5.     window.location.host              
    6. //获取当前窗口的端口  例如: 8080  
    7. window.location.port  
    8. //获取当前窗口的路径 例如: /shopping/buyCart.shtml  
    9.     window.location.pathname  
    10. //获取当前文档的Url  
    11.     document.URL  
    12. //获取参数  例如: ?skuId=510&amount=1  
    13. window.location.search  
    14. //跳出当前窗口,打开新窗口  
    15. window.open(url);  
    16. document默示的是一个文档对象,window默示的是一个窗口对象,一个窗口下可以有多个文档对象。
      所以一个窗口下只有一个window.location.href,然则可能有多个document.URL、document.location.href
    17. window.location.href和document.location.href可以被赋值,然后跳转到其它页面,document.URL只能读不克不及写

猜你喜欢

转载自www.cnblogs.com/shanghongyun/p/9949281.html