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.

alternative to include a file/script

Discussion in 'JavaScript' started by MyVodaFone, Jul 16, 2011.

  1. #1
    The script below alerts a message whether if I'm logged into facebook or not, instead of an alert for onLoad I want to include a <script .js file, has anyone any ideas how I can accomplish that.

    
    <script type="text/javascript" 
        src="https://www.facebook.com/people/Jens-Lübberstedt/1009310897"
        onload="alert('Logged in to Facebook')"
        onerror="alert('Not logged in to Facebook')">       
    </script>
    
    Code (markup):
    I basically want the page to include this <script src="example.js"></script> if onload is triggered.
     
    MyVodaFone, Jul 16, 2011 IP
  2. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #2
    not tested:
    
    
    <html>
    <head>
    function loadScript(){
    var headID = document.getElementsByTagName("head")[0];         
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = 'http://www.somedomain.com/somescript.js';
    headID.appendChild(newScript);
    }
    
    <script type="text/javascript" 
        src="https://www.facebook.com/people/Jens-Lübberstedt/1009310897"
        onload="loadScript"
        onerror="alert('Not logged in to Facebook')">       
    </script>
    
    </head>
    ...
    
    Code (markup):
     
    Jan Novak, Jul 17, 2011 IP