Loading ...
Sorry, an error occurred while loading the content.

Hard Challenge, Loading YAHOO scripts via a javascript file, with a Twist!

Expand Messages
  • John Hamman
    Hi all, I have an interesting challenge here. I am restricted by Corporate BS Redtape on how I can add content on some pages. I need to load JS files on a
    Message 1 of 5 , Nov 16, 2006
    • 0 Attachment

      Hi all, I have an interesting challenge here. I am restricted by Corporate BS Redtape on how I can add content on some pages. I need to load JS files on a page, but i dont have access to that html page, except in database driven content spots on the page. I would like to "import" the js into the head using a javascript method passed via those content spots in the body area of the html. So here is what I have. I have the following code in the content sections (This code could be repeated a few times).

      <body>
      <div>
      <script language="javascript" type="text/javascript" src="HTTPS:
      //someothersubdomain.cox.com/PageFunctions.js"></script>
      <script>
      <!--
      DoSomthing();
      //-->
      </script>
      </div>

      Now keep in mind, that the above code could be repeated a few times. i want to load up the YAHOO JS code AND if possible, reference it and use the onAvailable EVENT after its been loaded. Below is my attempt to do so, but its not working. The "test.js' file only has a window.alert() that just tells me its been loaded. Can someone help me with this unique challenge?

      var BA = window.BA || {};
          BA.pageFunctions = function() {
          var eJF = ['test.js','dom.js','event.js']; //dom and event are yahoo's js
          var YUD;
          var YUE; 
          return {
                     init : function() { 
                        for ( var i=0, j=eJF.length; i<j; ++i ) {
                          this.loadJSFiles(i,"HTTPS://SOMEOTHERSUBDOMAIN.DOMAIN.COM + eJF[i])
                        }
                     },
                     loadJSFiles : function(id,file) {
                        var head = document.getElementsByTagName('head').item(0)
                        var scriptTag = document.getElementById('loadScript' + id);
                        if(scriptTag) head.removeChild(scriptTag);
                        script = document.createElement('script');
                        script.src = file;
                        script.type = 'text/javascript';
                        script.id = 'loadScript';
                        head.appendChild(script);        
            
             }
          };
       }();

      I am no superJS coder, and would like to use yahoo code in these pages, but the restriction causes a unique issue. Another interesting twist is that these pages are on one SECURE subdomain, in which I cannot drop other files in, so I have access to another SECURE subdomain that I can work with. But they are both on the main domain.com address, just different subs.
      Please Help or give suggestions, or anything!
    • Matt Warden
      ... Can you explain a little why you want to do this in the head? I don t see any benefit, especially if you will have javascript scattered about the body
      Message 2 of 5 , Nov 16, 2006
      • 0 Attachment
        On 11/16/06, John Hamman <john.hamman@...> wrote:
        >
        > Hi all, I have an interesting challenge here. I am restricted by Corporate BS Redtape on how I can add content on some pages. I need to load JS files on a page, but i dont have access to
        >
        >

        Can you explain a little why you want to do this in the head? I don't
        see any benefit, especially if you will have javascript scattered
        about the body anyway.


        --
        Matt Warden
        Cleveland, OH, USA
        http://mattwarden.com


        This email proudly and graciously contributes to entropy.
      • John Hamman
        Hi Matt, well, simply thought it had to be loaded in the head. but if it doesn t then thats even better! I basicly need a way to use the yahoo lib, but cant
        Message 3 of 5 , Nov 16, 2006
        • 0 Attachment
          Hi Matt, well, simply thought it had to be loaded in the head. but if
          it doesn't then thats even better! I basicly need a way to use the
          yahoo lib, but cant write it into the head of the document. so I
          guess that gives me a challenge.

          --- In ydn-javascript@yahoogroups.com, "Matt Warden" <mwarden@...>
          wrote:
          >
          > On 11/16/06, John Hamman <john.hamman@...> wrote:
          > >
          > > Hi all, I have an interesting challenge here. I am restricted by
          Corporate BS Redtape on how I can add content on some pages. I need
          to load JS files on a page, but i dont have access to
          > >
          > >
          >
          > Can you explain a little why you want to do this in the head? I
          don't
          > see any benefit, especially if you will have javascript scattered
          > about the body anyway.
          >
          >
          > --
          > Matt Warden
          > Cleveland, OH, USA
          > http://mattwarden.com
          >
          >
          > This email proudly and graciously contributes to entropy.
          >
        • Matt Warden
          ... I hear different things, but some strongly suggest that it should actually be put in the body rather than the head. e.g.: http://www.crockford.com/ (see
          Message 4 of 5 , Nov 16, 2006
          • 0 Attachment
            On 11/16/06, John Hamman <john.hamman@...> wrote:
            >
            > Hi Matt, well, simply thought it had to be loaded in the head. but if
            > it doesn't then thats even better! I basicly need a way to use the
            > yahoo lib, but cant write it into the head of the document. so I
            > guess that gives me a challenge.
            >

            I hear different things, but some strongly suggest that it should
            actually be put in the body rather than the head. e.g.:

            http://www.crockford.com/
            (see JavaScript Files section)


            --
            Matt Warden
            Cleveland, OH, USA
            http://mattwarden.com


            This email proudly and graciously contributes to entropy.
          • Daniel Schmid
            Hi This works for me function include(script_filename) { document.write(
            Message 5 of 5 , Nov 16, 2006
            • 0 Attachment
              Hi This works for me

              function include(script_filename) {
              document.write('<' + 'script');
              document.write(' language="javascript"');
              document.write(' type="text/javascript"');
              document.write(' src="' + script_filename + '">');
              document.write('</' + 'script' + '>');
              }

              function include_dom(script_filename) {
              var html_doc = document.getElementsByTagName('head').item(0);
              var js = document.createElement('script');
              js.setAttribute('language', 'javascript');
              js.setAttribute('type', 'text/javascript');
              js.setAttribute('src', script_filename);
              html_doc.appendChild(js);
              return false;
              }

              include('/js/somefile.js');

              Daniel
              >
              >
              > Hi all, I have an interesting challenge here. I am restricted by
              > Corporate BS Redtape on how I can add content on some pages. I need to
              > load JS files on a page, but i dont have access to that html page,
              > except in database driven content spots on the page. I would like to
              > "import" the js into the head using a javascript method passed via those
              > content spots in the body area of the html. So here is what I have. I
              > have the following code in the content sections (This code could be
              > repeated a few times).
              >
              > <body>
              > <div>
              > <script language="javascript" type="text/javascript"
              > src="HTTPS://someothersubdomain.cox.com/PageFunctions.js"></script
              > <https://someothersubdomain.cox.com/PageFunctions.js%22%3E%3C/script> >
              > <script>
              > <!--
              > DoSomthing();
              > //-->
              > </script>
              > </div>
              >
              > Now keep in mind, that the above code could be repeated a few times. i
              > want to load up the YAHOO JS code AND if possible, reference it and use
              > the onAvailable EVENT after its been loaded. Below is my attempt to do
              > so, but its not working. The "test.js' file only has a window.alert()
              > that just tells me its been loaded. Can someone help me with this unique
              > challenge?
              >
              > var BA = window.BA || {};
              > BA.pageFunctions = function() {
              > var eJF = ['test.js','dom.js','event.js']; //dom and event are
              > yahoo's js
              > var YUD;
              > var YUE;
              > return {
              > init : function() {
              > for ( var i=0, j=eJF.length; i<j; ++i ) {
              >
              > this.loadJSFiles(i,"HTTPS://SOMEOTHERSUBDOMAIN.DOMAIN.COM + eJF[i])
              > }
              > },
              > loadJSFiles : function(id,file) {
              > var head =
              > document.getElementsByTagName('head').item(0)
              > var scriptTag =
              document.getElementById('loadScript' +
              > id);
              > if(scriptTag) head.removeChild(scriptTag);
              > script = document.createElement('script');
              > script.src = file;
              > script.type = 'text/javascript';
              > script.id = 'loadScript';
              > head.appendChild(script);
              >
              > }
              > };
              > }();
              > I am no superJS coder, and would like to use yahoo code in these pages,
              > but the restriction causes a unique issue. Another interesting twist is
              > that these pages are on one SECURE subdomain, in which I cannot drop
              > other files in, so I have access to another SECURE subdomain that I can
              > work with. But they are both on the main domain.com address, just
              > different subs.
              > Please Help or give suggestions, or anything!
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.