简体   繁体   English

参数列表后缺少Javascript)

[英]Javascript missing ) after argument list

I have this function, and I call it from PHP with onClick="login_f('.$return.')" But in Firefox it gives me an error "javascript missing ) after argument list" Any help? 我有这个功能,我用onClick =“ login_f('。$ return。')”从PHP调用它,但是在Firefox中,它给我一个错误“参数列表后缺少javascript”。

  function login_f(return_v){
    email = document.login.email.value;
    email2 = document.login.email2.value;
    if(email == "" || email2 == ""){
      if(readCookie("lang") == "it_IT")
        msg('<span style="color:#D90909">Compila tutti i campi!</span>'); 
      else
        msg('<span style="color:#D90909">Fill in all fields!</span>');
    }
    else if(email != email2){
      if(readCookie("lang") == "it_IT")
        msg('<span style="color:#D90909">Le email non coincidono!</span>');
      else
        msg('<span style="color:#D90909">The emails do not match!</span>');
    }
    else{
      var date = new Date();
      date.setTime(date.getTime() + (365*24*60*60*1000));
      var expires = "; expires=" + date.toGMTString();
      document.cookie = "email=" + email + expires + "; path=/sbm/";
      if(return_v == "" || return_v == null)
        window.location.href = "http://www.xriuk.com/sbm/";
      else
        window.location.href = return_v;
    }
  }

It looks like (based on where it is used) $return (and therefore return_v ) is a string. 看起来(基于使用它的地方) $return (因此return_v )是一个字符串。

If that's the case, then it needs quotes around it. 如果是这种情况,则需要在其周围加上引号。

I highly recommend using json_encode to embed ANY kind of variable, not least because it greatly helps prevent XSS. 我强烈建议使用json_encode嵌入任何类型的变量,这尤其重要,因为它极大地有助于防止XSS。

So your PHP becomes: 因此,您的PHP变为:

echo '...... onClick="login_f('.htmlspecialchars(json_encode($return),ENT_QUOTES)."');"....';

您可以这样做:

echo '<a ... onClick="login_f(\''.$return.'\')">....</a>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM