Including relative path

Posted by Community Admin on 03-Aug-2018 11:40

Including relative path

All Replies

Posted by Community Admin on 30-Sep-2012 00:00

When you create a new page you can include header links to css and js.  I have created a folder callled js that exists at the same level as App_Data. I wish to reference a file within the page header at this level but am unsure how the relative path should appear?

<script type="text/javascript" src="/js/myJavascriptFile.js"></script>
<script type="text/javascript" src=" ~/js/myJavascriptFile.js"></script>

Posted by Community Admin on 30-Sep-2012 00:00

The first one is what you want, the slash at the start denotes "Start at the web root".  The second wont work at all as the "~" denoates an asp.net relative link, but that's resolved in the asp.net controls serverside, it's not a browser thing.  So the only what to resolve a ~ is to put runat="server" in the markup, but in this case if you do that it'll try and run the SCRIPT serverside and tank on you :)

...so use the first option :)

Steve

Posted by Community Admin on 30-Sep-2012 00:00

Thank you Steve for your full answer

Posted by Community Admin on 30-Sep-2012 00:00

@Steve

Unless (of course) you were to override the main Render() event and process <script> tags. Not that I think it's a good idea, but I guess it's possible to do.

This thread is closed