window.location IE和Firefox/Chrome跳转不一致的问题
在使用window.location时,我们会发现IE和Firefox/Chrome的跳转不一致,采用以下代码可以解决:
function History(id, typeText) { var browser = navigator.userAgent; if (browser.indexOf("Chrome") != -1 || browser.indexOf("Firefox") != -1) { window.location = "PriceOverTime/Index/History"; } else { window.location = "Index/History"; } }
如上代码,IE是基于当前页面的路径来进行跳转,而Firefox/Chrome是基于base=ContextPath跳转。
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://" +request.getServerName()+":" +request.getServerPort()+path+"/" ; %> <base href="<%=basePath%>" >
注意,我的页面首部使用了base标签来设置固定的base=ContextPath。