1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript to load html code?

Discussion in 'JavaScript' started by rmkreeg, May 3, 2010.

  1. #1
    I'm rather new to this and I haven't seen this technique implemented, so I'm wondering if its common and/or if it will present any problems:

    In a file named topcode.txt (in the same directory as index.html)
    <a href="page.html" title="Page">
    <img src="banner.jpg" width="900" height="130" alt="Welcome" />
    </a>
    Code (markup):
    In index.html:
    <body>
    <script language="javascript" type="text/javascript">
    var topcode = new XMLHttpRequest();
    var vURL  = "http://"+self.location.hostname+"/topcode.txt";
    topcode.open("GET",vURL,false);
    topcode.setRequestHeader("User-Agent",navigator.userAgent);
    topcode.send(null);
    
    // write in code pulled from "topcode.txt"
    document.write(topcode.responseText);
    </script>
    </body>
    Code (markup):
    Thanks for any feedback!
    -Bob K.
     
    rmkreeg, May 3, 2010 IP
  2. Wtfuxbbq

    Wtfuxbbq Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That "loading" proccess is known as Ajax and it is fairly common. It's mainly used to send and receive data without having to direct to a new page.
     
    Wtfuxbbq, May 5, 2010 IP