我想用页面网址显示提醒

时间:2017-07-27 14:13:35

标签: javascript jquery

我正在尝试在用户无法使用网址值登录时显示提醒消息。

<script type="text/javascript">
<!--
   var retVal = confirm("Login FAILED! Do you want to continue ?");
   if( retVal == true ){
      window.location.href = "login.php";
      return true;
   }else{
      alert("User does not want to continue!");
      return false;
   }
//-->
</script>

这是网址值

/?redirect_to=%2Fstarstruckmedia%2F%3Flogin%3Dfailed%26redirect_to%3D%252Fstarstruckmedia%252F&login=failed

2 个答案:

答案 0 :(得分:1)

除非您在某个职能部门,否则您无法使用return。把这些行拿出来,你的代码就可以了。

&#13;
&#13;
var retVal = confirm("Login FAILED! Do you want to continue ?");
if(retVal){
   window.location.href = "login.php";
} else {
   alert("User does not want to continue!\n" + window.location.href);
}
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以使用window.location.href获取当前页面的网址。有关详细信息,请参阅this

&#13;
&#13;
   var retVal = confirm("Login FAILED! Do you want to continue ?");
   if( retVal == true ){
      window.location.href = "login.php";
   }else{
      alert(window.location.href);
   }
&#13;
&#13;
&#13;