尝试从用户尝试从新选项卡中动态打开的内容中获取从我动态获得的内容,它在新选项卡中处于打开状态,但是本地主机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"); } } 推荐答案您要么需要包含协议(" "," "等),当您调用 .open()方法调用时.
You either need to include the protocol ("", "", etc.) when you call the .open() method call.
示例:
var newWindow = this.nativeWindow.open("www.gmail");
或者,更好的是,您可以通过在URL前面仅添加"//"来使其成为无协议".
Or, better still, you can make it "protocol-less" by prepending just the "//" to the URL.
示例:
var newWindow = this.nativeWindow.open("//www.gmail");
当省略协议时,浏览器会假定您所引用的是相对URL.
When omitting the protocol, the browser assumes that you're referring to a relative URL.
更多推荐
新网址将附加到本地主机网址
发布评论