Hi this is my first question in this site.
My problem is-I have created a jsp where in i have given one link to call another jsp (already created by some one) in a popup window.On saving some details in child window i want those values to be accessed in my parent window.But i dont have the permission to change the code of child window jsp.
can anyone help me...?
Thanks,
the code i am using to open a popup is as follows.
function popUp(url){
alert("inside popup");
window.open(url,'newWindow','width=750,height=400,left=150,top=100,toolbar=no,resizable=true');
}
Provided the url does not violate the same origin policy, you can access the window properties via the return value of window.open(), eg
var windowRef = window.open(url, ...);
var someElement = windowRef.document.getElementById("element-id");
var someJavaScriptVar = windowRef.someVar;
Related
Is it possible to refresh a page from another page using Javascript or JQuery without opening the same page in a new tab.
JS:
var newtab = window.open('http://localhost:8081/app/home');
newtab.document.location.reload(true);
I tried the above, but here, it will open a new tab, with the same page, which is already opened in the browser.
Please suggest a method.
I got the idea from a previous Question , here they used window Object Reference to reload the popup window, but for me it wont work, because, the parent window and child window runs in 2 different ports. So using the same trick, what i did is :
HTML:
<a onclick="openNewTab()">app2</a>
<a onclick="refreshExistingTab()">Refresh</a>
JS:
<script>
var childWindow = "";
var newTabUrl="http://localhost:8081/app/home";
function openNewTab(){
childWindow = window.open(newTabUrl);
}
function refreshExistingTab(){
childWindow.location.href=newTabUrl;
}
</script>
refreshExistingTab() this instend of refreshExistingTab
take a look at https://developer.mozilla.org/en-US/docs/Web/API/Window.open
basically if you do window.open and specify a window name it will overwrite that window with the url you provided.
so if you open the page each time with same window name, it should overwrite it each time you do it again from that other page.
I have a page in which i m calling another popup by window.open method. The only thing how can i change a label in opener page from popup page while the popup page is still alive ie which is not closed yet
It's better to let the opener window take care of changing values by exposing a small API to the popup window.
I've outlined it here: javascript - pass selected value from popup window to parent window input box
It should be like this:
window.opener.document.getElementById('label1').value = "the new value";
<script>
function myFunction() {
var additionalWindow = window.open("/additional");
// Write on the additional window
additionalWindow.document.write('written from separate window');
// Call a function on the additional window
additionalWindow.someFunction();
}
</script>
Here's Mozilla's documentation on window.open().
I have created a form so the user can complete his name, last name, credit card number etc.
All the information is provided by the user.
When the user has ended his work he should press a button and a new window pops up with the user's information revised.
Anyone has a suggestion on this? I would be grateful.
opener.document.getElementById("text").value = txt;
You can reference the child window from the parent one and vice-versa. When you open a popup window with window.open(url, options), it returns a reference to the child window. You can add handlers to it. Using jquery:
var w = window.open(url);
$(w).load(function() {
alert("I've just loaded");
});
From the child window, you can use the variable opener to reference the parent window. So if you want to grab info from the parent window, you'll use something like (again jquery):
var first_name = $(opener.document).find('.first-name').text();
Got this info here: http://sharkysoft.com/tutorials/jsa/content/053.html
From a user experience point of view, if you just want to open a popup to confirm the data, without server side processing, I find opening a popup disturbing and would rather use an overlay on the same page.
If I open a window using
window.open('myurl.html', 'windowname', 'width=100,height=100');
How do I refer to the new window (from the same page that opened it) using 'windowname'? This question is specifically about this. I'm aware that I could save a reference to the handle by using "var mywin = window.open(...)" but I don't care about that in this situation.
Thanks, - Dave
In firefox (might work in other browsers too, but now it's not my concern) I was able to reference one window accross multiple page loads with
var w = window.open("", "nameofwindow");
This opens new window if it doesn't exist and return reference to existing window if it does exist without changing contents of the window.
With jQuery I was then able to append new content, to make quick collection of interresting links like this
$('body', w.document).append(link_tag);
If you didn't save a reference to the window then there is no way to restore it. However, if that window is still open and if the page loaded there belongs to the same domain as your page, you can run JavaScript code in it:
window.open("javascript:doSomething()", "windowname");
Whether that's sufficient in your scenario depends on what you are trying to achieve.
Petr is correct:
var w = window.open("", "nameofwindow");
works in all browsers, I am using it to retrieve the reference to the window object previously opened by a different page. The only problem is the initial opening of the page, if the popup does not exist, you will get a new window with a blank page.
I tried invoking a Javascript function inside the context of the other document in order to check whether I opened a new window or retrieved the already active page. If the check fails, I just invoke window.open again to actually load my popup content:
var w = window.open("http://mydomain.com/myPopup", "nameofwindow");
Hope that helps.
It is not possible. The windowName is just to be used in target="..." of links/forms or to use the same name again in another window.open call to open a new url in that window.
Try open that window with the name, but URL is '' again, to check if it's a blank window or not. If it's in open, then you will get the window; if not, a new window open, and you need close it.
Add the children in localStorage will help to prevent to open the new blank window.
Please check my code in https://github.com/goldentom66/ParentChildWindow
Sorry I am posting late, but if you still have the other window open, and they are on the same domain, you can run, on the first window:
function getReference(w) {
console.log('Hello from', w);
}
And on the second window:
window.opener.getReference(window);
afaik there's no way like windows['windowname'].
The 'windowname' assigned in window.open() can be addressed as a target in <a target="windowname" [...] >
Is there a way by which a user can click on a link in a webpage, which would then trigger a new window being opened up, which is then populated with content by javascript from the original page?
I need to write a self contained HTML file (so cannot use external links) that is able to BUILD a new window with predefined content...
Yes. JavaScript's window.open method should be used for opening a new window.
That method returns back an object corresponding to a new window, so your JavaScript code can now access new window's DOM objects using that object.
See this.
You can open a new window (window.open) and write the content of the inner document stream programmatically, using document.write.
function example () {
var newWindow = window.open('about:blank','name','height=400,width=500');
newWindow.document.write('<html><head><title>Test</title>');
newWindow.document.write('</head><body>');
newWindow.document.write('<p>Test page generated programmatically.</p>');
newWindow.document.write('</body></html>');
newWindow.document.close();
}
Here is a basic example of writing content to a child window:
child_window = window.open('', 'name', 'width=300,height=300');
child_window.document.write('<h1>Hello World</h1>');