Converting javascript into iframe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gwong123
    New Member
    • Jun 2007
    • 7

    Converting javascript into iframe

    Hey, I need to convert this javascript code into iframe. The javascript goes into a server and brings out an ad banner. The X's is the server IP.

    <script language="javas cript" type="text/javascript" src="http://XXX.XXX.XXX.XXX/blahblah/0000/blahblahblah.ph p"></script>

    What I need to do is convert that line of code into an iframe format so that it does the same job of going into the server and pulling out the banner. Right now if I just add on the iframe tags, all it does it return the server info.

    <iframe src="http://XXX.XXX.XXX.XXX/blahblah/0000/blahblahblah.ph p"></iframe>

    What I need is for the banner ad itself to be returned, not the server info. I'm not knowledgeable with converting from javascript to iframe, can anyone give me some help?

    EDIT: Something else I realized is that if I just put in <iframe></iframe>, it still returns server info even though I never specified a target URL src.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    I assume blahblah.php returns a Javascript file. Try putting it in a browser to see the output.

    Comment

    • gwong123
      New Member
      • Jun 2007
      • 7

      #3
      I placed the url into my browser and it returned all of this:

      [CODE=javascript]var js='http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390 C0A260146E8E208 0E.php';...[/CODE]
      snipped code because it was messing up formatting - moderator
      Last edited by acoder; Jun 21 '07, 09:13 AM. Reason: Code formatting

      Comment

      • gwong123
        New Member
        • Jun 2007
        • 7

        #4
        It's weird because this code works:

        <script language="javas cript" type="text/javascript" src="http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390 C0A260146E8E208 0E.php"></script>

        and it connects to the server, pulls out the banner ad and displays it. But when I try switching it to iframe, it doesn't work:

        <iframe src="http://XXX.XXX.XXX.XXX/bannercode/5251/04FF9A29A4ED390 C0A260146E8E208 0E.php"></iframe>

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          The reason why the first line works and the second one doesn't is that the output is Javascript. What you need to do is create another file with the first line then use that file in the iframe.

          Comment

          • gwong123
            New Member
            • Jun 2007
            • 7

            #6
            Oh great! That works! Thanks a bunch!

            Now I just want to ask is that I have 8 different ad servers. The site I am making with the iframes basically dives into each server and returns a banner ad from each server into a table.

            adservertest.ht ml (example site) is where I will be having 8 iframe lines each pulling a banner ad out from each of the 8 servers. Will I have to make an individual file to hold each of the javascript lines?
            In other words, do I have to do this?

            adserver1.html
            adserver2.html
            adserver3.html
            adserver4.html
            adserver5.html
            adserver6.html
            adserver7.html
            adserver8.html
            Each of the above contains the respective javascript line for that specific server.

            Then I have the adservertest.ht ml which contains 8 <iframe></iframe> lines for each of the 8 files. Is there anyway to do it so that I can make just one file containing the javascript lines for each server (instead of 8 seperate files) from which the adservertest.ht ml can pull it out from?

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              You could use the URL search property (link). So the file could be adserver.html?n um=1, and you could change the num value for the rest. In the actual file, you'd have to parse the search property (described in the link). If it equals 1, then write out the script tag for the first ad server, if 2, then for the 2nd server and so on.

              Comment

              • gwong123
                New Member
                • Jun 2007
                • 7

                #8
                Would it be possible for you to give me a very basic example of code so I can see how I would utilize the code to achieve the effect you mentioned with the URL arguments?

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  You could have something as simple as ?1 at the end of the URL.

                  Then in your file, you could have the following code:
                  [CODE=javascript]var num = location.search .substring(1);
                  switch (num) {
                  case 1: document.write( "<script src='...'><\/script>"); break;
                  case 2: ...
                  }[/CODE]

                  Comment

                  • adityasiriguppa
                    New Member
                    • Oct 2016
                    • 1

                    #10
                    Please help me in converting this to iframe
                    This is also a banner ad it works in blog but i want iframe

                    <script type="text/javascript" language="javas cript">
                    var aax_size='300x2 50';
                    var aax_pubname = 'aoebtech-21';
                    var aax_src='302';
                    </script>
                    <script type="text/javascript" language="javas cript" src="http://c.amazon-adsystem.com/aax2/assoc.js"></script>

                    Comment

                    Working...