我正在创建一个“在新选项卡中打开链接”。我正在使用 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,您需要包含协议(protocol):
window.open('http://127.0.0.1:3000');
错误消息有点误导,我认为这是一个错误。
关于javascript - 无法在 'open' : Unable to open a window with invalid URL 'Window' 上执行 '%3127.0.0.1:3000',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46421194/