SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    Non-Member
    Join Date
    Jan 2000
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a quickie: is it possible to place javascript within javascript? The following is the code I am using to create a pop-up for a picture gallery. I would like to place a banner from a banner exchange in bold under each photo. When I use the code below I get an error message:



    <SCRIPT language=JavaScript>
    <!--
    function openpic(pic_name) {
    myWin= open("", "displayWindow", "width=640,height=510,status=no,toolbar=no,
    menubar=no,scrollbars=yes,resizable=yes,alwaysraised=yes");

    myWin.document.open();
    myWin.document.write("<html><head><title>" + pic_name + "</title>");
    myWin.document.write("</head><BODY><center><TABLE CELLPADDING='0' CELLSPACING='0' WIDTH='468'>");
    myWin.document.write("<br><img src=kate/image"+ pic_name + ".jpg><br>");
    myWin.document.write("<br><br><BR><br><BR><br><BR>");
    myWin.document.write("<script language='javascript' type='text/javascript' src='http://www.linkbuddies.com/ad.go?id=134039+2&n=3'></script>");

    myWin.document.write("</center></body></html>");

    myWin.document.close();
    }

    //-->
    </SCRIPT>



    You may view the source code for the entire page at: http://www.litmania.com/bla/gallery.shtml

    Thanks very much for your help

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why can't you simply use your commands normally? I don't see the need for JavaScript inside JavaScript.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's like a recursive call, call to another javascript after execute the write command.
    I don't know if there is a way to work around but try to avoid that
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi nazam,

    Have you tried simply writing the following?

    myWin.document.write("<img src = 'http://www.linkbuddies.com/ad.go?id=134039+2&n=3'>");

    If you are simply downloading an image, it should work. If on the other hand, more is being downloaded, you may need the script tags.

    Out of curiousity what error message did you get? Your code above didn't have the '<img'.

    123finder: it's really not a recursive because the statement is being written to a new page, and once the new page is loaded, the original page's information is lost.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  5. #5
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is starting to sound like the "can you call an SSI from an SSI with an SSI page" question... lol.

  6. #6
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly - why would you need to use JavaScript within JavaScript? You're already in there! Just use the command accordingly.

    I know my pages don't look like this:

    <?php
    echo($name);
    <?php
    echo("hi");
    <?php
    echo("world");
    ?>



  7. #7
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What?!

    Oh geez.

    I gotta go fix some pages...

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hahahaha - you continue to crack me up. I can imagine that happening, too: someone reads a tutorial on PHP that doesn't make it clear that you only need to "switch on" to PHP once for all your commands, and that person does that for every line - yikes!

  9. #9
    Non-Member
    Join Date
    Jan 2000
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your suggestion Vincent Puglia + others.

    However, I'm not looking to simply download an image; I know how to do that. As you can see, the Javascript is from a banner exchange.

    So how would I incorporate it within a pop-up created with Javascript?

    I wish I was good enough to have become a football player instead of having to tackle these kind of problems

  10. #10
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Football is much less torturesome, nazam... lol.

    If I follow your approach, it looks like you're trying to create the entire page dynamically with the JS.

    Is there a reason you can't just put the material for this page in a standard HTML page, and simply use the JavaScript call to open the window with that page in it?


  11. #11
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by etLux
    Football is much less torturesome, nazam... lol.

    If I follow your approach, it looks like you're trying to create the entire page dynamically with the JS.

    Is there a reason you can't just put the material for this page in a standard HTML page, and simply use the JavaScript call to open the window with that page in it?

    Because he is dynamically creating the image name according to what link the user clicks...

  12. #12
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by TWTCommish
    Exactly - why would you need to use JavaScript within JavaScript? You're already in there! Just use the command accordingly.

    I know my pages don't look like this:

    <?php
    echo($name);
    <?php
    echo("hi");
    <?php
    echo("world");
    ?>


    because he is dynamically writing the html code in a NEW pop up window, and he wants the javascript to appear in the new popup window, not the window that has the javascript in it...get it?

  13. #13
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do I "git it"? Yes. And it appears Kate is definitely worth the effort.

  14. #14
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what?

  15. #15
    Non-Member
    Join Date
    Jan 2000
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I give up. I'm off to chomp marshmallows and then go to sleep.




  16. #16
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Vincent Puglia
    Hi nazam,

    Have you tried simply writing the following?

    myWin.document.write("<img src = 'http://www.linkbuddies.com/ad.go?id=134039+2&n=3'>");

    If you are simply downloading an image, it should work. If on the other hand, more is being downloaded, you may need the script tags.

    Out of curiousity what error message did you get? Your code above didn't have the '<img'.

    123finder: it's really not a recursive because the statement is being written to a new page, and once the new page is loaded, the original page's information is lost.

    Vinny
    Yeah, it's not exactly a recursive call, but the behaviour is like one. And you could also have recursion with 2 levels.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  17. #17
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look at the JS code the banner exchange is giving you through that URL. If it references objects that don't exist on the opened window, you'll have problems.
    Brad Ediger
    Chief Programmer
    DynamixPro - Revolutionize Your Future
    http://www.dynamixpro.com/


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
  •