Caligo Posted February 29, 2008 Share Posted February 29, 2008 Hey, guys. I'm getting myself into some JavaScript, nothing big, but I need help. I want to make it so i can click on an image (or link if the case may be) and a new window appears. Within the window I would like an image and a button to close the window. I have the code to do both, i have them both working separately, with the exception of I can't get the new window to close, but I do have a button there. I can get the button to work without creating a new window, so I know that code works. (I have looked around the w3schools site, that is how I learned to create the code, along with a book I have.)So I need:1) A new window2) An image in the window and3) A button in the window that closes the new window when clickedThanks for the help. Below is the code im working on. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>JS Testing</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /></head><script type="text/javascript">window.onload = displayImgFull;function displayImgFull() { for (var i=0; i<document.links.length; i++) { if (document.links[i].className == "displayImg") { document.links[i].onclick = newWindow; } }}function newWindow() { var imgWindow = window.open("images/gallery/landscape_1.jpg", "img", "height=300, width=300") imgWindow.document.write(images/gallery/landscape_1.jpg + function closeWindow() { window.close()} + "<input type='button' value='close' onclick='closeWindow()' />") return false;}</script><body><a href="#" class="displayImg" ><img id="image" src="images/gallery/landscape_1.jpg" /></a></body></html> Link to comment Share on other sites More sharing options...
jeffman Posted February 29, 2008 Share Posted February 29, 2008 How much of your newWindow() function actually works? For all the functionality you want, you would normally fill the window with an HTML document, static or created on the fly. But you're filling it with a jpg. I don't think you can write to a jpg.Anyway, document.write() is a totally 90s method that for some reason the writers of most of our examples chose as a model to demonstrate 80 gazillion functions. Eeuw. I think you'll be happier putting some HTML with a javascript and some data in that new window and let the script figure out just what the content should be. Link to comment Share on other sites More sharing options...
Caligo Posted March 2, 2008 Author Share Posted March 2, 2008 Well, I can get the function to work, but only one part at a time. For instance, I can either get the image to to show up or I can get the button to show up, but not both. Nor can I get the button to actually work. So, really, it would be much more useful to have html and JS, etc in the new window, but I have no clue how to do that. I have tried to do that, but again, I don't know how. So, if you could show me an example or something, that would be great. Link to comment Share on other sites More sharing options...
Synook Posted March 3, 2008 Share Posted March 3, 2008 window.open("myhtmlpage.html", "img", "height=300, width=300") Link to comment Share on other sites More sharing options...
Caligo Posted March 3, 2008 Author Share Posted March 3, 2008 window.open("myhtmlpage.html", "img", "height=300, width=300") Hey, thanks! I hadn't realized you could do it like that! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.