Calling an external list (blogroll) with JavaScript

Discussion in 'JavaScript' started by braiiins, Sep 14, 2008.

  1. #1
    I want to be able to create a list of links that can be called through JavaScript on multiple sites, something similar to blogrolling.com, but hosted on my own site. It seems like it should be simple enough, but I have no idea how to do it. I've searched the net over and over, and, unless I'm searching the wrong thing... I just can't find anything!
     
    braiiins, Sep 14, 2008 IP
  2. braiiins

    braiiins Guest

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So I've discovered I can do this with document.write

    I don't know anything about javascript, would this be ok?

    I've got something like this:

    document.write("<a href=\'http://example.com\'>Example</a>");
    document.write("<br />");
    document.write("<a href=\'http://example.com\'>Example</a>");
    document.write("<br />");
    document.write("<a href=\'http://example.com\'>Example</a>");

    It works fine on my side, but will it work cross browser? Is it the right way to do this?
     
    braiiins, Sep 15, 2008 IP
  3. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah I think that should be ok.

    Not sure exactly how you're doing it , but you can call a php script from a javascript tag like <script src="http://mysite.com/script.php"></script> and then have the php fetch the results or whatever and then just send javascript output. The javascript output could be as simple as the lines you posted above.
     
    LogicFlux, Sep 15, 2008 IP
  4. braiiins

    braiiins Guest

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Would that be better than <script type="text/javascript" src="script.js"></script> ?
     
    braiiins, Sep 15, 2008 IP
  5. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well if you call a php script, you can generate the links dynamically that will be output via javascript.

    If you only use javascript you will pretty much be limited to using a static list of links, which means you'll have to update them manually.

    Or you could run a php script on the server side that isn't accessible to the public that runs with cron(you schedule how often it runs) to generate your link list and then dump the output to a plain .js file. Then you just call the .js file like normal from your html page.

    It just depends on exactly what your needs are.

    You can also call script.js and configure things on your server so it's executed as php, but that's a whole other topic and probably not what you're worried about right now.
     
    LogicFlux, Sep 15, 2008 IP