如何设置弹出窗口标题?

时间:2015-01-08 21:06:48

标签: javascript html css angularjs

我试图通过提供标题和网址来打开一个新的弹出窗口。我有类似的东西。

HTML

<a href="#" ng-click="openLink(link)">Open me<a>

我的控制器文件。

$scope.openLink = function(link) {
    $window.open(link.url).document.title = link.title
}
 //I am sure link.title is not undefined.   

上面的代码将使用url打开新标签页。但是,我想控制弹出窗口的标题。那可能吗?

网址和我的网站位于同一个域中。即使目标网址没有设置标题属性,我上面的代码也不会设置标题。我有一个类似的帖子,但它不是角度解决方案。 How to set the title for the new browser tab? 有没有办法以角度方式修复它。非常感谢!

1 个答案:

答案 0 :(得分:0)

由于 $ window 仅引用该窗口,因此基本上window.open(link.url)可供您使用

var win = window.open('', 'foo', ''); // open popup

function check() {
    if(win.document) { // if loaded
        win.document.title = "test"; // set title
    } else { // if not loaded yet
        setTimeout(check, 10); // check in another 10ms
    }
}

check(); // start checking

在加载页面时设置标题。代码直接来自Stewie Griffins' answer

相关问题