如何用其他协议打开路由?

时间:2016-03-11 15:46:08

标签: javascript ember.js

我有使用http打开的ember应用程序,但我有视频聊天按钮但WebRTC仅适用于https页面。所以我需要在新窗口中打开路由并使用https协议。我可以使用link-to吗? 我的链接:

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

现在我在控制器操作中使用window.open,但有些浏览器阻止打开窗口。

1 个答案:

答案 0 :(得分:2)

您可以通过将渲染锚点的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 }; 来实现。
添加以下初始值设定项:

protocol

在您的模板中添加新的{{#link-to "videochat" model.id classNames="call-button" target="_blank" protocol='https'}} Call {{/link-to}} attr:

{{1}}