获取浏览器的地址
一、在javascript中获取地址
window.location.href和document.location.href 、document.URL都可以获取浏览器的地址,他们的区别是:
1、window表示的是一个窗口对象,document表示的是一个文档对象,一个窗口下可以有多个文档对象。所以一个窗口下只有一个window.location.href,但是可能有多个document.URL、document.location.href;
2、window.location.href和document.location.href可以被赋值,然后跳转到其它页面,document.URL只能读不能写;
3、document.location.href和document.location.replace都可以实现从A页面切换到B页面,但他们的区别是:
用document.location.href切换后,可以退回到原页面,而用document.location.replace切换后,不可以通过“后退”退回到原页面。
4、document的对象
document.url 返回前一页的地址
document.referrer 返回当前页的地址
二、在servlet中获取地址
1、request.getHeader("host") 请求的地址
2、request.getHeader("Referer") 请求的完整地址
3、request.getHeader("Accept-language") 语言
4、request.getrequestUrl 获取的执行的地址