Not signed in (Sign In)

Vanilla 1.0.3 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorbrent3721
    • CommentTimeOct 31st 2007
     
    Is it possible to add the script tag to your pages with another javascript file. Say for instance you already have a global.js file linked into all your pages could you use the DOM to add the tag, I seem to be able to add it fine but it doesn't work too well on all browsers once added. I'm adding it to the page with an onPageLoad event, here's the function:

    // Add SWFObject to our pages ~ http://blog.deconcept.com/
    function AddSWF() {
    var headID = document.getElementsByTagName("head")[0];
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = '/includes/swfobject.js';
    headID.appendChild(newScript);
    }

    any way to make something like that work or is it not worth it?

    b r e n t
    • CommentAuthorAran
    • CommentTimeOct 31st 2007
     
    Brent

    This should work. Are you also waiting for onPageLoad to call your swfobject construction code? Because if you are waing to onLoad before you include the .js file, but you have othe javascript blocks in the body calling the swfobject constructor, it may be trying to initalise before you actaully have swfobject.js loaded....

    Aran
    • CommentAuthorbrent3721
    • CommentTimeOct 31st 2007
     
    Aran, that is probably the problem, how would I have the constructor code wait for the page to load?
    • CommentAuthorAran
    • CommentTimeOct 31st 2007
     
    You would need to have some over-arching javascript function which gets called on onLoad which calls AddSWF() and then runs another function which does your construction in the right place. It might get kind of painful if you have multiple divs / flash files you want to place on the pages.

    Does your server have the ability to serve dynamic pages like php? Because it would be a lot easier to have a head.php include which does the javascript inclusion for you on each page. Either that or use something like a Dreamweaver template which has that code baked into every page you produce.
    • CommentAuthorbrent3721
    • CommentTimeNov 1st 2007
     
    I am running PHP and could easily work it in that way, I was just thinking that it should be included with javascript because if someone's computer doesn't support javascript they don't need the tag and it's just an extra piece of code littering the HTML, although it seems like the work necessary outweighs the benefits. Thanks for your help!