无法在 'Window' 上执行 'open':无法打开具有无效 URL '%3127.0.0.1:3000' 的 window

Failed to execute 'open' on 'Window': Unable to open a window with invalid URL '%3127.0.0.1:3000'

我正在制作 "open link in new tab"。我正在使用 window.open() 打开新标签页。

我的代码:

$scope.doOpenLink = ()->
    domain = '127.0.0.1'
    port = '3000'

    window.open("#{domain}:#{port}");

但是我得到这个错误:

Error: Failed to execute 'open' on 'Window': Unable to open a window with invalid URL '%3127.0.0.1:3000'.

at MyServerScopeController.vm.doOpenLink (base-adb5b1181b.js:4294)
at fn (eval at compile (angular-29115c1a5c.js:15156), <anonymous>:4:286)
at callback (angular-29115c1a5c.js:26744)
at Scope.$eval (angular-29115c1a5c.js:17972)
at Scope.$apply (angular-29115c1a5c.js:18072)
at Scope.scopePrototype.$apply (hint.js:1558)
at HTMLAnchorElement.<anonymous> (angular-29115c1a5c.js:26749)
at HTMLAnchorElement.dispatch (jquery-888d4551b8.js:4737)
at HTMLAnchorElement.elemData.handle (jquery-888d4551b8.js:4549)

我的域 '127.0.0.1:3000' 呈现为 '%3127.0.0.1:3000'。关于如何解决它的任何想法?谢谢

问题不在于您的字符串是如何呈现的,如果您在 Chrome 浏览器控制台中 运行 以下代码,您会得到同样的奇怪错误:

window.open('127.0.0.1:3000');

您尝试打开的字符串无效 URL,您需要包含协议:

window.open('http://127.0.0.1:3000');

错误消息有点误导,我认为这是一个错误。