[removed] sending custom parameters with window.open() but its not working

前端 未结 5 1607
一整个雨季
一整个雨季 2021-02-14 05:58




         


        
5条回答
  •  遥遥无期
    2021-02-14 06:14

    To concatenate strings, use the + operator.

    To insert data into a URI, encode it for URIs.

    Bad:

    var url = "http://localhost:8080/login?cid='username'&pwd='password'"
    

    Good:

    var url_safe_username = encodeURIComponent(username);
    var url_safe_password = encodeURIComponent(password);
    var url = "http://localhost:8080/login?cid=" + url_safe_username + "&pwd=" + url_safe_password;
    

    The server will have to process the query string to make use of the data. You can't assign to arbitrary form fields.

    … but don't trigger new windows or pass credentials in the URI (where they are exposed to over the shoulder attacks and may be logged).

提交回复
热议问题