Execute contents inside . But myMethod() is not executed, cos the script is loaded sfter the page is parsed. – MeanMan Jun 06 '13 at 09:04

  • Use built-in browser's network capture feature to see if the script is loaded or not. I checked and did not see it loaded. It's only loaded when we insert script tags. – Khanh TO Jun 06 '13 at 09:07
  • 4 Answers4

    2

    It seems you jquery selector is not correct. It should be

    $("#loadmenu").attr("src",SRConfig.WESHost + "/webapp/" + SRConfig.WESApp+ "/servlet/WPSNav?mod=iwswps&idkey=displayhome");
    
    • As Live java said "The script is being loaded fine from the specified source", I'm guessing this is a copy/paste error, and `loadmenu` is defined in his/her code. – Guillaume Algis Jun 05 '13 at 10:52
    • come on,its a copy paste error!I have debugged using firebug, the script is getting loaded – MeanMan Jun 06 '13 at 08:31
    • @Dropout: this does not work. The OP has updated the question. – Khanh TO Jun 06 '13 at 08:46
    • @KhanhTO thanks for the info, but this was not my answer.. I was just pointing out that the aforementioned user had a good point regarding jQuery syntax. – Dropout Jun 06 '13 at 10:58
    1

    Insert script tag instead:

    $(document).ready(function(){
        var scriptTag = $("<script/>");
        scriptTag.attr("src",SRConfig.WESHost + "/webapp/" + SRConfig.WESApp+ "/servlet/WPSNav?mod=iwswps&idkey=displayhome");
        $("head").append(scriptTag);
    });
    

    or use a similar code of facebook.

    (function(d, s, id){
         var js, fjs = d.getElementsByTagName(s)[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement(s); js.id = id;
         js.src = "Your URL";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'loadmenu'));
    
    Khanh TO
    • 48,509
    • 13
    • 99
    • 115
    0

    Take a look at Detect if page has finished loading if it helps you.

    Basically you can use .load function with window to see if it's fully loaded and trigger your script after that.

    Documentation:

    http://api.jquery.com/load-event/

    Community
    • 1
    • 1
    Dropout
    • 13,653
    • 10
    • 56
    • 109
    0

    Is there a reason you are modifying the src attribute in javascript ?

    If the script path to load is determined by the hosted web application, I'm guessing you could simply do something like:

    <script id="loadmenu" src="${SRConfig.WESHost}/webapp/${SRConfig.WESApp}/servlet/WPSNav?mod=iwswps&idkey=displayhome"></script>
    

    The ${} being replaced in your html template by your server side app.

    I'm not familiar with the technology behind theses SRConfig.* so I could be totally wrong.

    Guillaume Algis
    • 10,705
    • 6
    • 44
    • 72