Pop up window getting replaced if opened from another session - javascript

In Java web application (JSF), I have a Person form which has Add details button on click of this button, i'm opening a pop up window using java script but i haven't closed this pop up window yet. Now if i open a another session of the same application and try to add details for another person, it replaces the pop up window which was opened with previous session. How to avoid such scenario ?
var url = contextpath+'person/AddDetails.jsp';
var modalprops = "height=310,width=400,scrollbars=on,status=no;menubar=no,resizable=no";
window.open(url, 'adddetails', modalprops, false);
I'm not good at UI technologies :(, hence this question.

Give each window a unique name instead of having them all be called "adddetails".

Related

How to trace the child windows opened in javascript

i have three links in my page, i want to restrict the user to open a link one at a time. So how to check through javascript when user clicks on a link whether it has been opened already a window or not(by opened i mean not just click the link and close it, the window should be opened at the time when user clicks on link).
Give the windows a name, then you can access them using the DOM. Every time a user opens a new popup window you could run a loop that will try and access all the popups. If another window is open already you can stop the current popup event from happening.
The popups would all have to be under your domain for this to work.

Redirect after clicking an external link and only open one tab/window

I have created a jsp for external clients of my application to use to link to the web client. They can specify which client they are in the URL so that when the link opens a window it is named and any other links from that client will open in the same window. Here's an example URL:
mysite.com/redirect.jsp?fromClient=mine&page=awesome
The problem is that when you click on this link, for example from an email digest, it opens the redirect.jsp page which uses window.open() to open the desired page. From the above link, the page that would open would be:
mysite.com/index.jsp?page=awesome
So then I have two pages open, when really I only want one. And since I'm not using javascript to open the first page (it's a link), I can't use window.close() to close it. I've tried working around using window.open('','_parent','') and window.open('','_self','') but neither works.
I know there has to be a better way to redirect than to open a second window from my jsp page, but I don't know what that better way is. Thoughts?
EDIT
Primary goal is for users of external clients to be able to click links in that client and have all the links take them to the same window/tab in a browser. I'm using window.open right now because I can parse the link and get the client name and then supply that in the window.open function.
EDIT 2
I always end up being too vague in these questions. Ok, here's the setup:
An email digest contains a link that looks like
mysite.com/redirect.jsp?fromClient=emailDigest&pageNum=4
Currently, when that link is clicked on, it opens a browser (duh) and then the redirect.jsp page parses that link to get the client name, in this case emailDigest. It then calls window.open('mysite.com/index.jsp?pageNum=4','emailDigest'). This creates a new window with the name emailDigest unless a window/tab with that name already exists, in which case it merely updates the URL in that window with the new one.
I want to either be able to close the original window (the one with the redirect.jsp address) or not have to open that initial window at all.
NOTE
As there are many different clients that want to be able to do this, I cannot guarantee that they will be creating the link with HTML so the target attribute is not the answer.
The correct answer is "No, it cannot be done". If you do not open a window with Javascript then you cannot close it with Javascript. I would always have to create at least 2 windows, which is not what we wanted.
I think you're looking for window.location instead of window.open.
Please use window.location.replace("http://mysite.com/index.jsp?page=awesome");
Reason :
replace(url):Replace the current document with the one at the provided
URL. The difference from the assign() method is that after using
replace() the current page will not be saved in session history,
meaning the user won't be able to use the Back button to navigate to
it.
As haynar says above, why do you open a window and not either:
<!-- content contains the refresh delay in seconds and the target url -->
<meta http-equiv="Refresh" content="1; URL="http://mysite.com/index.jsp?page=awesome">
or use javascript to do the same:
window.location.href = "http://mysite.com/index.jsp?page=awesome";
either works fine and will leave you with one window open.
To get the named window use a targeted link:
Mysite.com
This will automatically set the name property of the opened window.

Close window using JavaScript

I have a window(1) that has a button(1). If I click on the button, then another window(2) will appear. It also has a button(2). If I click on the button (2) then popup will appear. How can I close the window(2) if I press "OK" on the popup window? I am using javascript.
// store reference to window
var window2 = window.open(...);
// close window via reference, put this in your OK button handler
window2.close();
Read here about window management.
You cannot do it according the security assurance of browser, there
are some action which doesn't allow to be managed directly via
javascript without user interference.
Got this from here /stackoverflow/

close pop up window and redirect to parent window in struts2

I have pop up window , in which to upload an excel file of adding new users.
After clicking the button and successfully added the users into DB, I want to close the pop up window and refresh the parent window to see the updates. In Parent Window, it shows the list of users.
How can I handle all of these events and steps in Struts2 and javascript?
function callAddUsers() {
document.frmUpload.action = "addUsers.action";
document.frmUpload.submit();
}
I want to display some messages of how many users added in parent window too. How can I pass all those info by action?
Now the problem is when I successfully uploaded and added users, the popup window displays the list of users and I have two window opened.
Thanks.
Simple solution.
just window.close(); the popup window and target="main" , in here just target name of the parent window. all works perfectly :)

How to close parent window on child window open using window.open()

Using javascript "window.close()" method after opening new window using "window.open", it serve the problem i.e. but it will ask a confirmation message to user whether he really wants to close the window or not... if user selects yes then the parent window will close and if not then he will remain on the same window and new window will not get open up..
So is there any way so that parent window will get closed without asking any confirmation message and new window will gets open up ?
No. It´s a security feature. You are trying to manipulate an application on another users machine.
If you put it in another context it becomes clear why it is as it is and why it should be that way: Would you like if your email client suddenly closed cause you read an email?
EDIT: What you can do is having the login window trigger a navigate event in it´s opener so the first page gets replaced by the billing info page. Then it can close itself.

Categories

Resources