新网址将附加到本地主机网址 [英] New url is getting appended with localhost url

查看:56
本文介绍了新网址将附加到本地主机网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从用户尝试从新选项卡中动态打开的内容中获取从我动态获得的内容,它在新选项卡中处于打开状态,但是本地主机URL随动态URL一起添加.

Url what i am getting from dynamically from user that i am trying to open in a new tab, its getting open in new tab but the localhost url is getting appended along with the dynamic url.

      @Injectable()
    export class WindowRef {
        constructor() {}
        getNativeWindow() {
            return window;
         }
    }

export class UrlTab implements OnInit{

          constructor(private winRef: WindowRef) {
           this.nativeWindow = winRef.getNativeWindow();
       }

    //method getting called on click of <a></a> from html
          assignActity(type: string): void {
           var newWindow = this.nativeWindow.open("www.gmail.com");
    }
}

推荐答案

您要么需要包含协议(" http://"," https://"等),当您调用 .open()方法调用时.

You either need to include the protocol ("http://", "https://", etc.) when you call the .open() method call.

示例:

var newWindow = this.nativeWindow.open("http://www.gmail.com");

或者,更好的是,您可以通过在URL前面仅添加"//"来使其成为无协议".

Or, better still, you can make it "protocol-less" by prepending just the "//" to the URL.

示例:

var newWindow = this.nativeWindow.open("//www.gmail.com");

当省略协议时,浏览器会假定您所引用的是相对URL.

When omitting the protocol, the browser assumes that you're referring to a relative URL.

这篇关于新网址将附加到本地主机网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆