SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    Import js link from within another js link?

    Hello,

    I'm trying to combine a few Google Custom Search js snippets and links into one file. Mainly for ease of editing. This is going in .html pages. I know I could use .htaccess to run php on the page in order to use SSI's but it's not worth the possible performance hit for this one piece as the rest of the site is plain html. I figured I would just use document.write to insert the script link into the other but this does not work for some reason. Save the document.write lectures please. Should this work? Or maybe something about the google script needs to run on it's own? Or should this not work and you know how to make it work? Thanks!

  2. #2
    SitePoint Enthusiast TriLLi's Avatar
    Join Date
    Feb 2010
    Location
    BiH, Bugojno
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    maybe you are doing it wrong, you can do it like this:

    1. Link one js file
    2. in linked js file put script which will load javascript:

    Example
    Code JavaScript:
    var ar = new Array();
    ar.push('www.google.com/custom.js');
    ar.push('www.wiseblog.info/tag.js');
    for(var i = 0; i < ar.length; i++)
    {
     var el = document.createElement('script');
     el.setAttribute('type', 'text/javascript');
     el.setAttribute('src', ar[i]);
     document.getElementsByTagName("head")[0].appendChild(el);
    }

    I hope that this will help you
    http://www.wiseblog.info
    Programmers don't die, they just GO SUB without return.

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Hello, unfortunately I can't do that because the link does not reside on my server. Normally I would just copy and paste it onto to mine but it's a large google search script. Who nows how often they update that ya know.

  4. #4
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Secondly, if you put a document.write statement in a external js script is the document.write stuff cached along with the external js link?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •