Search code examples
javascripthtmlflashswfobjectfilepath

How can I make the relative paths to JS & SWF files in HTML work?


I have created a simple flash menu and the SWF file, JS files (swfoject.js and flying.js) & XML files are in a folder called "icpmenu_es" on the server root. If I open the SWF file on my local HDD it works fine but if I alter the paths to the files for use on my website, it won't work at all. I know it has found the JS files because if I put an incorrect path in it comes up with the message saying that I need to install Flash or allow JS to access the menu. The code is as follows:

<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="keywords" content="" /> <meta name="description" content="TEST" /> <meta http-equiv="Content-Language" content="es" /> <base href="http://www.ideal-country-property.com/"></base> <title> TEST | Ideal Country Property S.L.</title>
<script type="text/javascript" src="icpmenu_es/swfobject.js"></script>
<script type="text/javascript" src="icpmenu_es/flying.js"></script></HEAD><BODY> <!-- ICP www.ideal-country-property.com -->
<div id="ICPmessage" style="position:absolute; top:100px; padding-left:0px; z-index:0;">
    You need to upgrade your Flash Player or to allow javascript to enable Website menu. </br>
    <a href="http://www.adobe.com/go/getflashplayer">Get Flash Player</a>            
</div>
<script type="text/javascript">
// <![CDATA[
    var so = new SWFObject("icpmenu_es/menu.swf", "menu", "185", "440", "8", "#000000");
    so.addVariable("page_code", "a_b_c");

    so.addParam("wmode", "transparent");
    so.addParam("scale", "noscale");
    so.addParam("salign", "TL");
    so.write("ICPmessage");
// ]]>
</script></BODY></HTML>      

Any help would be much appreciated as this is driving me crazy and it seems such a simple thing. By the way, if I change the BASE attribute to the icpmenu_es folder then it works as all the src links just have the "filename" and not the path. However, I can't change the BASE attribute to this folder as I have other scripts running on our Website in different locations and it would then mess these up! Thanks in advance for your help. Chris.


Solution

  • Once you put this on your web server preceeding the path with / will mean that anything that wishess to access it will go to the root of the domain,

    /yourfolder/javascript.js

    if you simply use

    yourfolder/javascript.js

    and for example, your current path on your site is

    www.yoursite.com/members

    then that relative path will be translated into

    www.yoursite.com/members/yourfolder/javascript.js

    So using absolute, it will always know to go to the root of your site to file the files!

    UPDATE:


    Use the following markup and test

    <HTML> 
    <HEAD> 
        <title>ICP Spanish Menu</title> 
    <base href="http://www.ideal-country-property.com"></base>  
        <script type="text/javascript" src="/icpmenu_es/swfobject.js"></script> 
        <script type="text/javascript" src="/icpmenu_es/flying.js"></script> 
      </HEAD> 
    <BODY> 
    <!-- ICPmessage www.ideal-country-property.com --> 
        <div id="ICPmessage" style="position:absolute; top:100px; padding-left:0px; z-index:0;"> 
            You need to upgrade your Flash Player or to allow javascript to enable Website menu. </br> 
            <a href="http://www.adobe.com/go/getflashplayer">Get the FREE Flash Player from Adobe</a>            
        </div> 
    <div id="menu"></div>
        <script type="text/javascript"> 
        // <![CDATA[
            var so = new SWFObject ("/icpmenu_es/menu.swf", "menu", "185", "440", "8", "#000000");
            so.addVariable("page_code", "a_b_c");
    
            so.addParam("wmode", "transparent");
            so.addParam("scale", "noscale");
            so.addParam("salign", "TL");
            so.write("ICPmessage");
        // ]]>
        </script> 
    </BODY> 
    </HTML>