2016-03-11 29 views
0

我有用http打開的應用程序應用程序,但是我有用於videochat的按鈕,但WebRTC只能在帶有https的頁面上工作。所以我需要在新窗口中打開路由並使用https協議。我可以用link-to嗎? 我的鏈接:如何用另一個協議打開路由?

{{#link-to "videochat" model.id class="call-button" target="_blank"}}Call{{/link-to}}

現在,我在控制器動作window.open做,但有些瀏覽器塊中打開的窗口。

+0

爲什麼不在你的應用程序中使用HTTPS無處不在? –

+0

這是一個問題。 – Dmitro

+0

這是最簡單的解決方案。我沒有看到你的域名只有一個特定的URL會使用HTTPS。 –

回答

2

您可以通過將呈現的錨點的href屬性重新綁定到新的計算屬性hrefWithProtocol來實現此目的。
添加以下初始化:

// app/initializers/customize-link-to.js 

import Ember from 'ember'; 

const { 
    LinkComponent, 
    computed 
} = Ember 

export function initialize() { 

    LinkComponent.reopen({ 
    attributeBindings: ['hrefWithProtocol:href'], 
    hrefWithProtocol: computed('href', 'protocol', function() { 
     let { 
     href, 
     protocol 
     } = this.getProperties('href', 'protocol'); 

     if (protocol) { 
     href = protocol + '://' + window.location.host + href; 
     } 

     return href; 
    }) 
    }) 
} 

export default { 
    name: 'customize-link-to', 
    initialize: initialize 
}; 

在模板中添加新 ATTR:

{{#link-to "videochat" model.id 
    classNames="call-button" 
    target="_blank" 
    protocol='https'}} 
    Call 
{{/link-to}}