Problem running function in .js file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sl1ver
    New Member
    • Mar 2009
    • 196

    Problem running function in .js file

    I have a tiny problem.

    I have used this function in the HTML page and it works but doesn't when i call it from a js file

    HTML CODE
    Code:
    script language="javascript" src="../js/Menu.js">
    
                        var page1 = window.location.pathname
                        page = setMenuTop(page1);
                        document.write(page);
        
    </script>
    JS CODE
    Code:
    function setMenuTop(sPath)
    {
        var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
        var sPageName = sPage.replace('.aspx', '');
    
        if (sPageName === '100') {
            sPageName = 'Top 100';
        }
        if (sPageName === 'Main') {
            sPageName = 'Home';
        }
    
        return sPageName;
    }
    It does not write any code once the page is loaded and i can't see what i'm doing wrong here.
  • Sl1ver
    New Member
    • Mar 2009
    • 196

    #2
    This problem is solved. I took the main query out of the "head" of the html code but just references my .js page from there and then put all the code i need where i needed it and it worked.

    Comment

    Working...