Results 1 to 2 of 2

Thread: Need some Popup Window Help

  1. #1
    Join Date
    Jul 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need some Popup Window Help

    I have a bunch of thumbnail pictures on various pages of my site, and I've made a popup.js to open up a page displaying the photo and a close button. Now I've decided that I want to add a description to some of the photos and this has been causing me some trouble. Here is the code for popup.js:
    Code:
    var newwindow
    
    function popimage(url , title , note) {
    	if (newwindow && !newwindow.closed)
    		{ newwindow.focus(); newwindow.document.clear() }
    	else
    		{ newwindow=window.open('','','width=875,height=575,top=50,left=50') }
    newwindow.document.writeln('<html>');
    newwindow.document.writeln('<head>');
    newwindow.document.writeln('<script language="JavaScript" src="vars.js" type="text\/javascript"><\/script>');
    newwindow.document.writeln('<title>' + title + ' Image<\/title>');
    newwindow.document.writeln('<style type="text\/css" media="screen">@import url("style_2008.css")\;<\/style>');
    newwindow.document.writeln('<\/head>');
    newwindow.document.writeln('<body>');
    newwindow.document.writeln('<div style="margin-top: 5px"><center><img src="' + url + '" alt="Image">');
    	if (note!=null || note!="")
    		{newwindow.document.writeln('<br \/><script type="text\/javascript">document.write('note');<\/script><br>')};
    newwindow.document.writeln('<form>');
    newwindow.document.writeln('<input type="button" value="Close Window" onClick="window.close()">');
    newwindow.document.writeln('</form><\/center>');
    newwindow.document.writeln('<\/div>');
    newwindow.document.writeln('<\/body>');
    newwindow.document.writeln('<\/html>');
    newwindow.document.close();
    }
    My call on my website looks like:
    Code:
    <a href="javascript:popimage('/images/chainlink_lrg.jpg','Boat Photo','txt')"><p>Enlarge</p></a>
    And the file vars.js just holds a bunch of variables with strings of text in each one (one for each different photo that I want to have a description). For right now the only line in it is:
    Code:
    var txt="This is a sample of a description"
    So if I don't put in the 3rd argument, it works just fine showing the photo and the close button. However if I put in my variable "txt" the photo and close button don't show up in the new window and only the text string "this is a sample of a description" appears (well in Firefox that is... in IE it just crashes). I'm close but I've obviously got the syntax wrong or something. Or maybe I'm just way off base with trying to show the description with a nested document.write? I'm trying to make this work without having to put my description into the 3rd argument, and only want to put something simple (and cleaner looking then a paragraph of text) like a variable that is unique to that photo. In any event some help would be greatly appreciated!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,957
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    Code:
    var newwindow
    
    function popimage(url , title , note) {
    	if (newwindow && !newwindow.closed)
    		{ newwindow.focus(); newwindow.document.clear() }
    	else
    		{ newwindow=window.open('','','width=875,height=575,top=50,left=50') }
    newwindow.document.writeln('<html>');
    newwindow.document.writeln('<head>');
    newwindow.document.writeln('<script language="JavaScript" src="vars.js" type="text\/javascript"><\/script>');
    newwindow.document.writeln('<title>' + title + ' Image<\/title>');
    newwindow.document.writeln('<style type="text\/css" media="screen">@import url("style_2008.css")\;<\/style>');
    newwindow.document.writeln('<\/head>');
    newwindow.document.writeln('<body>');
    newwindow.document.writeln('<div style="margin-top: 5px"><center><img src="' + url + '" alt="Image">');
    	if (note)
    		newwindow.document.writeln('<br>' + note + '<br>');
    newwindow.document.writeln('<form>');
    newwindow.document.writeln('<input type="button" value="Close Window" onClick="window.close()">');
    newwindow.document.writeln('</form><\/center>');
    newwindow.document.writeln('<\/div>');
    newwindow.document.writeln('<\/body>');
    newwindow.document.writeln('<\/html>');
    newwindow.document.close();
    }
    And when you pass the variable to the call, it shouldn't be quoted, you also should not use javascript:whatever in the href (messes up sometimes in some browsers):

    Code:
    <a href="/images/chainlink_lrg.jpg"  onclick="popimage(this.href,'Boat Photo', txt);return false;">Enlarge</a>
    Alternatively, you could pass a literal text string, then it should be quoted:

    Code:
    <a href="/images/chainlink_lrg.jpg"  onclick="popimage(this.href,'Boat Photo', 'This is a sample Note');return false;">Enlarge</a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •