The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Need help with Javascript code

DavaDava Registered User regular
edited June 2008 in Help / Advice Forum
Okay, so I've decided to add my webcomic to a banner exchange, since I could use the increase in traffic. I have the code I'm supposed to insert on my webpages. I'm decent with (X)HTML, but I don't know much at all about Javascript. Still, I'm looking at this code, and it doesn't look right to me. W3C seems to agree, since it doesn't validate on my pages. I'm pretty sure there's a better way to write this.
<!-- EasyBanner Pro code begin -->
<script language="JavaScript" type="text/javascript">
<!--
document.write('<s'+'cript language="JavaScript" src="http://www.rubifruit.com/exchange/work.php?n=18&size=1&j=1&c=1&code='+new Date().getTime()+'"></s'+'cript>'); 
// --> 
</script>
<noscript>
<iframe src="http://www.rubifruit.com/exchange/work.php?n=18&size=1&c=1" width="468" height="70" style=" margin:0 ; border: 0; overflow: hidden;"></iframe>
</noscript>
<!-- EasyBanner Pro code end -->

The doctype I'm using is XHTML 1.0 Transitional, so obviously, the iframe is the first thing that needs to go. The code needs to work on both .html and .php files. Other than that, I have no idea what I need to do.

petition_banner.JPG
Dava on

Posts

  • flatlinegraphicsflatlinegraphics Registered User regular
    edited June 2008
    ok, the script is breaking the actual html output into chunks to get around no-script/ad blocker software.
    document.write('<s'+'cript language="JavaScript" src="http://www.rubifruit.com/exchange/work.php?n=18&size=1&j=1&c=1&code='+new Date().getTime()+'"></s'+'cript>');
    actually outputs:
    <script language="JavaScript" src="http://www.rubifruit.com/exchange/work.php?n=18&size=1&j=1&c=1&code=datestamp"></script&gt;

    the iframe is what actually pulls the banner in and displays it. unless you want to much around with innerHTML calls and possibly violating your terms of service, just paste in the script and forget about it.

    and according to some quick googling, frames/iframes are not INvalid, its just that you have to use the right dtd.. and the containing page needs to validate too.
    http://www.webmasterworld.com/forum21/8803.htm

    flatlinegraphics on
  • DavaDava Registered User regular
    edited June 2008
    Hey, thanks for the reply!

    My site is large, and frankly, I'm not changing the doctype on all my files just to join some banner exchange. Not worth it! I changed the code to this, and it looks like it works. It validates on W3C.
    <!-- EasyBanner Pro code begin MODDED-->
    <script language="JavaScript" type="text/javascript">
    <!--
    document.write('<s'+'cript language="JavaScript" src="http://www.rubifruit.com/exchange/work.php?n=18&amp;size=1&amp;j=1&amp;c=1&amp;code='+new Date().getTime()+'"></s'+'cript>'); 
    // --> 
    </script>
    <noscript>
    <span class="adbox">
    <img src="http://www.rubifruit.com/exchange/work.php?n=18&amp;size=1&amp;c=1" width="468" height="70" alt="Rubifruit Banner Exchange" /></span>
    </noscript>
    <!-- EasyBanner Pro code end -->
    

    I changed each & to & which made the validator happy. And I changed the iframe to a plain img. Is that kosher? Anything else I could tighten up?

    Dava on
    petition_banner.JPG
  • flatlinegraphicsflatlinegraphics Registered User regular
    edited June 2008
    if it still actually works, and displays the banner, than great. just most of the time, an & in a url, esp an active page call, is a delimiter to pass a variable. so using html entities may not be 100% kosher. you can look up the url encodings for the charecter, but the ampersand is actually valid in that circomstance. the validator is probably picking up on it because it is generated text, rather than something like a link.

    plus, if they are doing a php call, rather than linking straight to the image, its probably for an add rotator script. who knows.

    just be careful about modifying these types of things, as it could violate your terms of service.

    is the validator giving you warnings, or errors?

    flatlinegraphics on
  • DavaDava Registered User regular
    edited June 2008
    The validator only gave me errors for the ampersands. Once I added the url encodings, it seemed fine. I'm not too concerned about violating terms of service. I know the girl who runs the banner exchange, and she admitted to me that she doesn't know much about Javascript. I told her the code she provides isn't valid for my doctype, and she told me to just find some way to make it work. Fun times!

    Dava on
    petition_banner.JPG
  • DavaDava Registered User regular
    edited June 2008
    Solved!

    OMG, I can't believe I missed this. Instead of an iframe, it should be an object. That way, the PHP can rotate the banners. Hur hur! I was able to eliminate the javascript completely.

    Thanks for the help, guys.
    <!-- EasyBanner Pro code begin MODDED-->
    <object data="http://www.rubifruit.com/exchange/work.php?n=18&amp;size=1&amp;c=1"
    type="text/html" width="478" height="80">
    <p>Proud member of <a href="http://www.rubifruit.com">Rubifruit</a>: Good things by/for/about women.</p>
    </object>
    <!-- EasyBanner Pro code end -->
    

    Dava on
    petition_banner.JPG
Sign In or Register to comment.