MrCat Posted May 16, 2011 Share Posted May 16, 2011 I'm using <base href> to set my HTML path for links, and chdir() to set PHP's base path. (Entering site at www.mysite.com/account then resetting my paths back to root for simplicity). Both of these are working fine, however I've found Javascript ignores <base href> so it's working directory is still a subfolder of root. OK - so I could add '../' to all Javascript links (which is what I was trying to get away from!) but I've read that it's only IE that ignores <base href> and other browsers accept it. This will mean my links break unless I either stop using <base href> entirely and go back to using '../' in ALL links, or I can find a way to set Javascript's base link pointer... This is driving me crazy! Any ideas of how to do it? Quote Link to comment https://forums.phpfreaks.com/topic/236514-can-i-set-javascripts-base-href-base-url-for-all-relative-links/ Share on other sites More sharing options...
JasonLewis Posted May 16, 2011 Share Posted May 16, 2011 Generally what I do is in the head of my document, prior to loading any JavaScript files I'll create a JavaScript variable 'g_url' and set this to my sites base URL, which is set via PHP. <script type="text/javascript"> var g_url = 'http://www.yourbaseurl.com/'; </script> Quote Link to comment https://forums.phpfreaks.com/topic/236514-can-i-set-javascripts-base-href-base-url-for-all-relative-links/#findComment-1216023 Share on other sites More sharing options...
MrCat Posted May 16, 2011 Author Share Posted May 16, 2011 Thanks for that. I have decided to do similar to what you've suggested and completely re-organised the links in my site now. Was hoping for a quick fix but I don't actually think it was possible! Quote Link to comment https://forums.phpfreaks.com/topic/236514-can-i-set-javascripts-base-href-base-url-for-all-relative-links/#findComment-1216282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.