By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,978 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,978 IT Pros & Developers. It's quick & easy.

java script for popup window

P: n/a
i need a javascript for popup window and how to pass value to that new
window from old window .

Dec 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sangram wrote:
i need a javascript for popup window and how to pass value to that new
window from old window .
// creating:
var myNewWindow =
window.open("someurl.html","mywin","width=300,heig ht=200");

// passing info
myNewWindow.document.someJSFunction('Hi');

in someurl.html:
<script type="text/javascript">
function someJSFunction(str){
alert(str);
}
</script>

One warning: If you call a function in someurl.html immediately after
creating it, chances are that the window did not load, so the function will
not be there.
If you want to circumvent this problem, let the popupwindow tell the parent
window it loaded, and start calling function in the popup AFTER it told the
parent it loaded.

To do this, simply put a call like this in the popup:
<body onLoad="parent.document.popuploaded();">

And in the parentwindow create that popuploaded() function and add some
logic to it so the parent knows that the popup is ready to be called.

Regards,
Erwin Moller

Dec 1 '06 #2

P: n/a
ASM
Erwin Moller a écrit :
sangram wrote:
>i need a javascript for popup window and how to pass value to that new
window from old window .
(snip)
If you want to circumvent this problem, let the popupwindow tell the parent
window it loaded, and start calling function in the popup AFTER it told the
parent it loaded.
.... after it told the opener it is loaded
To do this, simply put a call like this in the popup:
<body onLoad="parent.document.popuploaded();">
doubt that will work ... ? !
The popup has no 'parent' but has an 'opener'.
>
And in the parentwindow create that popuploaded() function and add some
logic to it so the parent knows that the popup is ready to be called.
except the parent is not parent but opener ..;
In JS of main (mother) page :
=============================

var truc = false;

function pop() {
if(truc && !truc.closed) truc.close();
truc = window.open('','','width=450,height=380,resizable= 1');
truc.onload = doThat();
truc.focus();
}
function doThat() {
var d = truc.document;
d.open();
d.write('<h1>hello !<\/h1>');
d.close();
}

function popText(vari) {
if(truc && !truc.closed) truc.close();
truc = window.open('','','width=250,height=90,resizable=1 ');
truc.document.open();
truc.document.write(vari);
truc.document.close();
truc.focus();
}

var someText = '<h1>Saluti<\/h1>';
var someJS = '<script type="text/javascript">'+
'opener.doThat();'+
'<\/script>';

in html :
=========

<a href="#" onclick="pop();return false;">
pop 1</a><br>
<a href="#" onclick="popText(someText);return false;">
pop 2 : text by variable</a><br>
<a href="#" onclick="popText('is it OK?');return false;">
pop 2 : text written in call</a><br>
<a href="#" onclick="popText(someJS);return false;">
pop 2 : JS written (using variable)</a><br>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.