Removing screen from Stack after navigating to another screen - javascript

I have a TabNavigator with two Tabs A Tab and B Tab.
In B, there is a StackNavigator C Stack. From within this stack, I navigate via navigation.navigate('A Tab') to Tab A. How can I reset B Tab, that when the user navigates back to B Tab, there is not the Stack, but the TabNavigator?
I tried
navigation.reset({
index: 0,
routes: [{name: 'B Tab'}],
});
This removes the tack, but this navigates to the sreen B Tab which I do not want. I want to stay on current screen.

Related

window.open remove reference from parent

I have one page with list of reports and after clicking on report it redirects me to internal report page in new tab with:
window.open(reportIdUrl,reportId);
So when i am back on report list and i want to open same report i will use
window.open("",reportId);
if(redirect.location.href === "about:blank" || redirect.location.href !== '<internalreportpage>') {
redirect = window.open(reportUrl,reportId);
redirect.focus();
} else {
redirect.focus();
}
But when someone from new tab with internal report page navigates somehow to report list page (within this tab) and then tries to open internal report page it will open it in same tab as it is tab reference not content reference.
Does anybody know some way to drop reference when i access if condition?
Something like:
window.open("",reportId);
if(redirect.location.href === "about:blank" || redirect.location.href !== '<internalreportpage>') {
window.dropReference(reportId) //change_me
redirect = window.open(reportUrl,reportId);
redirect.focus();
} else {
redirect.focus();
}
So it will create new tab with new reportId reference?
Thanks
EXAMPLE
--reportlistpage
linkToReport1 (window.open(report1Url,1))
linkToReport2 (window.open(report2Url,2))
.
.
.
You click on linkToReport1 - 2 tabs are opened. One with reportlistpage and one with internal-report/report1.
You go back to parent tab and click to linkToReport1. Tab is opened with reference to "1" and will focus to it and no new tab is opened (this is ok).
You are on linkToReport1 and you redirect with some menu hyperlink to reportlistpage (within linkToReport1 tab). Url changed to /report-list
You click to linkToReport1. Nothing happen (this is not ok) because you are on the tab with reference to 1 (content and url changed), now you want to open a new tab with /internal-report/report1 url and store it as 1 with window references.
I figured it out. It is bit simple when you realize you can set or reset window.name. So there is nothing like references from parent.
Based on content you can do something following. In the page you want to keep track in tab,
at the beginning (in my case internalReport id):
var currentWindow = window.self;
currentWindow.name = reportId; //this is in case someone manually opened it without window.open(internalReportUrl, reportId)
then bind resetting of window.name on beforeunload event (e.g.):
var resetWindowName = function() {
var currentWindow = window.self;
currentWindow.name = ""
}
window.addEventListener('beforeunload', resetWindowName);
So when you redirect from internalreportpage somewhere, name is cleared and you can repeadetly call
window.open(internalReportUrl,reportId)
which will open new tab for you.

<a target="main" issue in case of two different session

I have child window which has a hyperlink. On click of hyperlink i have to redirect to parent window. I could do this using following syntax-
<a target="main" href='${pageContext.request.contextPath}/xyz/abc.jsp?id=123'/>
Suppose i have two parent window (P1 and P2) with two different session (S1 and S2 respectively) open. If i try to open child window from P2 and click on hyperlink, it redirects to P1 window. This behavior is very inconsistent. How can i ensure that hyperlink on each child window updates to their respective parent window ?

Obtain reference to existing browser window

I'm 99% sure that the answer to my question will be no but just in case...
Use case:
Webpage A opens a new window B with JavaScript (same domain)
The user refreshes A or navigates away and then returns
The user clicks on a link in page A which should close B
This works fine by holding on to the window reference as long as the user does not refresh and navigates away from A (step 2).
Is there any (exotic or not) way to re-obtain the reference to the previously opened window(s) when returning to A?
Yes
function openWin() {
w = window.open("","windowname"); // use the window name you gave it when you opened it
if (w && !w.closed) ...
}

Javascript Popup Window as a singleton

I have a page A which opens a javascript window as myWin = window.open(..). Now in another page B in the same domain, when user clicks on a link, I want to check if myWin is available, if yes then bring that window in front, else do a new myWin.
The problem I have is the window.js file in both pages and window.js contains the line
var myWin = null;
Within Page A scope, my logic works and brings window to front. Within Page B it works as well. Howver when I open window in Page A, click on link in Page B, it fails.
It is as if myWin is reset to null in scope of Page B. How can I overcome this problem? Pointers??/
The popup window is created by page A and only page A contains a reference to that window. When you open page B, there is no way to pass page A's reference to the popup over to page B. This cannot be done.
You want to call window.open with an empty url, e.g.
var newWindow = window.open('', title, dimension); // title needs to be a constant
if (newWindow.location.href && newWindow.location.href!='about:blank') {
// Window was already open and points to something
newWindow.focus();
} else {
// new window make it point to something
newWindow.location.href = 'http://yoursite';
}
This assumes that the popup is opening a window within the same site as the calling page, since otherwise you can encounter various permissions issues.

javascript refresh popup from another popup

Window A opens window B
Window A opens window C
On Window C (after user action) I need Window B refreshed.
some more explanation:
yes. Window A is the main calendar. window B is opened manually and is smaller and shows stats about the calendar (window A)
When user clicks on a calendar event in window A then Window C opens. And when the user changes info on Window C then Window B (stats) needs to update.
First of all I have to warn you that what you are trying to achieve is not a good practice.
Many browsers are opening new tabs instead of new windows, which can influence the availability of the window.opener . Although this depends heavily on the browser settings.
So first of all you should test to see that your code is really opening new windows, not new tabs.
Now, in a.html you should have this:
var windowB=window.open("b.html");
var windowC=window.open("c.html");
In c.html you should have this:
function openNewPage() {
window.opener.windowB.location.reload(true);
}
and call the openNewPage() function on user interaction.
You need to set references to each other the child windows to each other. Here's a simple demo.
var b= window.open('');
var c= window.open('');
b.test=function() {
alert('Function in window B');
};
c.test=function() {
b.test();
return false;
};
$(b.document).find('body').append('<div>Window B. Click here</div>');
$(c.document).find('body').append('<div>Window C. Click here</div>');
http://jsfiddle.net/9ZCX3/25/

Categories