新网址将附加到本地主机网址

编程入门 行业动态 更新时间:2024-10-26 00:31:35
本文介绍了新网址将附加到本地主机网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试从用户尝试从新选项卡中动态打开的内容中获取从我动态获得的内容,它在新选项卡中处于打开状态,但是本地主机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.

更多推荐

新网址将附加到本地主机网址

本文发布于:2023-10-31 18:34:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主机   网址   新网址

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!