ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Javascript not working same through weblog like it does static in template

August 31, 2007 4:05am

Subscribe [1]
  • #1 / Aug 31, 2007 4:05am

    If I type in the following script to remove the white backgrounds from pngs in ie 6 the script does the desired job.

    <!--[if lt IE 7]>
    
    function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
    {
       var arVersion = navigator.appVersion.split("MSIE")
       var version = parseFloat(arVersion[1])
       if ((version >= 5.5) && (document.body.filters)) 
       {
          for(var i=0; i<document.images.length; i++)
          {
             var img = document.images<i>
             var imgName = img.src.toUpperCase()
             if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
             {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "             var img + img.style.cssText              if (img.align == "left") img + imgStyle             if (img.align == "right") img + imgStyle             if (img.parentElement.href) img + imgStyle
                var strNewHTML = "<span></span>" 
                img.outerHTML = strNewHTML
                i = i-1
             }
          }
       }    
    }
    window.attachEvent("onload", correctPNG);
    
    <![endif]-->

    If I make a weblog like below and just copy in the script into the blog with no formating it outputs the same thing to my browser but it does not work. Any Ideas?

    {exp:weblog:entries weblog="java_png" dynamic="off"}
    {body_field}
    {/exp:weblog:entries}
  • #2 / Aug 31, 2007 4:43pm

    Lisa Wess

    20502 posts

    Hi,

    Can you clarify what you’re doing? You’re trying to store that Javascript in a weblog entry for some reason? Or are you putting it in one of your templates?

    Also, can you post a link to the problem page?

  • #3 / Aug 31, 2007 4:51pm

    I guess the problem is because the javascript has to get run first. If its in the weblog then its being added as information and does not get run.

  • #4 / Aug 31, 2007 5:08pm

    Lisa Wess

    20502 posts

    I’m still not following.  Can you break down *exactly* what you’re doing, what the problem is, and where we can see it?

  • #5 / Aug 31, 2007 5:14pm

    Im all set now. I know what the problem is. Javascript has to get run first. Since I was putting javascript in the weblog it was getting parsed last and not working. I guess I just need to call it from an external file.

  • #6 / Aug 31, 2007 5:25pm

    Lisa Wess

    20502 posts

    You can always place it in a JS type template, instead. I suspect that the weblog custom field formatting or some such was actually interfering, but I’m glad you got it working!

  • #7 / Aug 31, 2007 5:33pm

    Heres what I did: I added this line in the template and made a separate javascript template and put the script in there.

    {embed="home/png"}
  • #8 / Aug 31, 2007 5:37pm

    Lisa Wess

    20502 posts

    That’s not really the best way to handle it. You should be calling that with script tags, like so:

    <script src="{path="home/png"}"></script>

    Or have your script entirely in the embedded template as a static template type, including the opening and closing script tags, then embed it.  It’s one or the other, though, just like in HTML. =)

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases