We can open a Window in Java Script using
window.open("url", "MsgWindow");
and we can provide a name to it in place of windowName. This method opens a new window and assigns it a name("MsgWindow" in this case).
Now if we again call
window.open("url", "MsgWindow");
then it replaces the window which was opened in the previous call.
Lets say you have to open a document which contains n number of Pages on a Click event,
Scenarios :
1) If the Doc is not opened then open the document in new Tab
2) If the Doc is already opened then just switch to it
3) If the Doc is already opened but we need to view a different page then replace the Opened tab with new tab and the new page
Every time we open a window we can add the windowName to a collection such as a Map.
Lets say docid is the name of the document.
We can use docid as the windowName and either switch to the window if the window is already opened or open a new window.
popupIndex : number = 0 ;
static window_map = new Map<number,Window>();
{
URL= window.location.origin + "/showpdf/" + docid;
if(this.popupIndex === 0)
CandidatesComponent.windowMap.set(parseInt(docid) ,
window.open(URL,docid));
if(this.popupIndex !== 0)
{
var windowFound : Boolean = false;
CandidatesComponent.windowMap.forEach(( value: Window ,key: number) =>
{
if(key == docid)
{
CandidatesComponent.windowMap.set(parseInt(docid),window.open(URL,docid));
windowFound = true;
return;
}
})
if(!windowFound)
{
CandidatesComponent.windowMap.set(parseInt(docid),
window.open(URL,docid))
return;
}
}
this.popupIndex ++ ;
}, 250)
CandidatesComponent.windowMap.forEach(( value: Window ,key: number) =>
{
if(key == docid)
{
CandidatesComponent.windowMap.set(parseInt(docid),window.open(URL,docid));
windowFound = true;
return;
}
})
if(!windowFound)
{
CandidatesComponent.windowMap.set(parseInt(docid),
window.open(URL,docid))
return;
}
}
this.popupIndex ++ ;
}, 250)
No comments:
Post a Comment