2017-05-17 40 views
1

Url我從用戶動態獲得的信息,我試圖在新選項卡中打開,它在新選項卡中打開,但本地主機url正在隨動態url一起追加。新的URL正在追加localhost 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"); 
    } 
} 

回答

2

你要麼需要包括協議( 「http://」, 「https://」 等),當你調用.open()方法調用。

例子:

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

或者更好的是,你可以把它 「協議少」 由剛剛在前面加上 「//」 的URL。

實施例:

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

當省略協議,瀏覽器假定你指的是相對URL。

+0

它的工作,謝謝。 –

+0

但有一個問題是當前窗口在重新打開新窗口時重新加載。 –