2017-09-26 55 views
2

我正在製作一個「在新標籤頁中打開鏈接」。我正在使用window.open()打開新標籤頁。未能在'窗口'上執行「打開」:無法打開具有無效網址'%3127.0.0.1:3000'的窗口'

我的代碼

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

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

,但我得到這個錯誤:渲染爲'%3127.0.0.1:3000'

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'。關於如何修復它的任何想法?由於

+1

你的代碼中'#{}'的用途是什麼?爲什麼不會;你只是'window.open(「http://127.0.0.1:3000」)' –

+0

@JaromandaX那是[咖啡腳本字符串插入器](https://coffeescript-cookbook.github.io/chapters/字符串/插值) –

+0

哦,沒錯,沒有看到代碼是coffeescript,認爲這是javascript –

回答

0

的問題不在於你的字符串是如何呈現的,如果你運行在Chrome瀏覽器控制檯下面的代碼,你會得到同樣奇怪的錯誤:

window.open('127.0.0.1:3000'); 

你試圖打開的字符串是不是一個有效的URL,你需要包括協議:

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

錯誤信息有點誤導,我會說這是一個錯誤。

+0

謝謝你。固定! –