当前位置: 代码迷 >> JavaScript >> JS回获取页面的URL top.location.href 和 window.location.href
  详细解决方案

JS回获取页面的URL top.location.href 和 window.location.href

热度:171   发布时间:2012-11-23 22:54:33.0
JS来获取页面的URL top.location.href 和 window.location.href

JS来获取页面的URL:

(1)普通的格式是:window.location.href

(2)但是如果是登录时候先弹出个对话框,这个对话框里面是登录的页面login.jsp,这个时候在这个对话框里面如果想获取最外层的url的方式,就必须用 top.location.href 了。

?

例子如下:

var strHref = top.document.location.href;
var intPos = strHref.indexOf("#");
var strRight = strHref.substr(0,intPos);
if(num == "success"){
	top.location.href = strRight;
}else if(num !== "null"){
	document.getElementById("error_login").innerHTML = num;
}

?

另外还有一种情况是:

????? 在form提交表单的时候有个属性可能对上面的(2)的情况有用target="_top"

<form name="loginForm" action="Login.action" method="post" target="_top">

</form>

  相关解决方案