471,049 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

java script for popup window

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

Dec 1 '06 #1
2 2194
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
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.

Similar topics

3 posts views Thread by Raju V.K | last post: by
reply views Thread by evander | last post: by
1 post views Thread by bubipoo | last post: by
11 posts views Thread by Wentink | last post: by
2 posts views Thread by Dennis | last post: by
6 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.