After I create another window, I want to be able to click on a link and change an image on the parent window. I was only able to change the image from the parent itself. But this is not what I want.
parent.html contains:
<html>
<head>
<script language="javascript1.2">
<!-- hide from old browsers
window.name = "QuizWindow";
function NewWindow(mypage, myname, w, h, scroll)
{
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable,dependent=yes'
optWindow = window.open(mypage, myname, winprops);
if (parseInt(navigator.appVersion) >= 4) { optWindow.window.focus(); }
}
//-- stop hiding--->
</script>
</head>
<body>
<a href="child.html" onClick="NewWindow(this.href,'optWindow','300','400','yes'); return false;">Create a window</a>
<a href="javascript :" onMouseOver="window.document.img1.src='ss.gif'" onMouseOut="window.document.img1.src='so.gif'"><img name="img1" src="so.gif" border=0></a>
<p>
<a href="javascript ://"><img name="img2" src="so.gif" border=0></a>
</body>
</html>
--------------
child.html contains:
<html>
<head>
<script language="javascript1.2">
<!-- hide from old browsers
function NewWindow(mypage, myname, w, h, scroll)
{
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
optWindow = window.open(mypage, myname, winprops);
if (parseInt(navigator.appVersion) >= 4) { optWindow.window.focus(); }
}
function writeBack(Obj,imgName)
{
//var win = window.opener.name;
//win.document.open();
//win.document.img2.src = imgName;
parent.document.img2.src = imgName;
//win.document.close();
//alert ("parent: " + win + " - self.name: " + self.name);
}
//-- stop hiding--->
</script>
</head>
<body>
<a href="javascript ://" onClick="writeBack('img2','ss.gif'); return false;">Write image</a>
</body>
</html>
------
The comment parts are things that I have tried, but they don't work either. Any help will be greatly appreciated.
Thanks!
If you want to see this running, go to: http://acm.calstatela.edu/scripts/
You're SO close.
In your writeBack function, change parent.document to window.opener. That should do it.
Thank you so much. It's working now. But how would you pass an object as a parameter? For example, I want to do this:
<a href="javascript ://" onClick="writeBack(win.opener.document.img2,'ss.gif'); return false;">Write image</a>
Then the function writeBack takes two parameters. One object and another is the image location.
function writeBack(Obj, imgName) {
Obj.src = imgName;
}
This is not working.... any idea how to do this?
Thanks in advance.
Oooh.. never mind. Figured it out.
writeBack(win.opener.document.img2,'ss.gif')
should be
writeBack(window.opener.document.img2,'ss.gif')
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks