【问题标题】:i want to add credentials to window.open(url) in angular6我想在 angular6 中向 window.open(url) 添加凭据
【发布时间】:2020-06-10 09:09:37
【问题描述】:

Code output

我在 window.open 中遇到了这个问题 下面是代码

  repourl:any='http://192.168.1.104/....'
 ngOnInit() {
 var params = {
  Username: 'd2kuser',
  Password: '****'};window.open(this.repourl);

有什么方法可以在寡妇打开的情况下传递凭据。

【问题讨论】:

  • 您是否尝试过在第一行中使用“user:password@url”格式?如果是通过基本身份验证,那么应该可以。

标签: angular angular6 angular8 angular4-httpclient


【解决方案1】:

在 URL 中添加用户名和密码作为查询参数。它会起作用的。

【讨论】:

    【解决方案2】:
        form = document.createElement("form");
       form.action = url;
       form.method = verb;
       form.target = target || "_blank";
       if (_data) {
           var data = _data.split("&")
           for (var key = 0; key < data.length; key++) {
               var input = document.createElement("textarea");
               input.name = data[key].split("=")[0];
               input.value = data[key].split("=")[1];
               form.appendChild(input);
           }
       }
       form.style.display = 'none';
       document.body.appendChild(form);
       form.submit();
    

    对相同的提交表单操作使用不同的方法

    【讨论】:

      猜你喜欢
      • 2014-06-15
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多