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 badges2 Answers
Reset to default 3try 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.