最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open only one popup tab with angular - Stack Overflow

programmeradmin0浏览0评论

I wondered how to open only one tab and before you can open another tab, the previous tab has to be closed. I open the tab with a button click,

onClick(){
        let url = this.router.createUrlTree(['/user/', this.id]);
        window.open(url.toString(), "_blank", "resizable=no, toolbar=no, scrollbars=no, menubar=no, status=no, directories=no, location=no, width=1000, height=600, left=" + horizontal + " top=100 " );
        console.log(this.data.maxtab);
        } 

It leads to a ponent "user" which is nested in another ponent.

And when one is opened and try to open another ponent, the one, which is opened should be focused.

I tried to change a variable, which I called maxtab on ngOnDestroy of the ponent but it does not work. How can I achieve it? With OnBeforeunload with JS (looked it up but could not implement it) or are there another ways?

I wondered how to open only one tab and before you can open another tab, the previous tab has to be closed. I open the tab with a button click,

onClick(){
        let url = this.router.createUrlTree(['/user/', this.id]);
        window.open(url.toString(), "_blank", "resizable=no, toolbar=no, scrollbars=no, menubar=no, status=no, directories=no, location=no, width=1000, height=600, left=" + horizontal + " top=100 " );
        console.log(this.data.maxtab);
        } 

It leads to a ponent "user" which is nested in another ponent.

And when one is opened and try to open another ponent, the one, which is opened should be focused.

I tried to change a variable, which I called maxtab on ngOnDestroy of the ponent but it does not work. How can I achieve it? With OnBeforeunload with JS (looked it up but could not implement it) or are there another ways?

Share Improve this question asked Mar 8, 2019 at 9:19 Anna MarieAnna Marie 913 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

try this,

declare a variable in the ponent.ts

private mywindow;

Now in your function, try this:

if(this.mywindow) {
 this.mywindow.close();
}
this.mywindow = window.open(url.toString(), "_blank", "resizable=no, toolbar=no, scrollbars=no, menubar=no, status=no, directories=no, location=no, width=1000, height=600, left=" + horizontal + " top=100 " );

You should use name parameter, to provide name of window.

window.open(URL, name, specs, replace)

example:

var myWindow = window.open(url.toString(), "mypopup", "resizable=no, toolbar=no, scrollbars=no, menubar=no, status=no, directories=no, location=no, width=1000, height=600, left=10 top=100");
if (myWindow) {myWindow.focus()}

You can give any name in place of "mypopup".

With that you need not to close the earlier popup, it will open the new url, with in same popup window.

myWindow.focus() will set focus to the already open popup, while opening the new url provided.

发布评论

评论列表(0)

  1. 暂无评论