limitphp Posted February 4, 2009 Share Posted February 4, 2009 In html, we can set the base of all hrefs and imgs, etc with: <base href="<?php echo SITEURL;?>"/> Is there a similar thing we can do to set all the href calls in javascript? So, when we are on a mod rewrite page like localhost/artist-name/ and we want to make a href call in our javascript it will set it to the correct base directory, localhost/ ? Thanks Link to comment https://forums.phpfreaks.com/topic/143775-solved-setting-the-base-for-all-hrefs/ Share on other sites More sharing options...
dennismonsewicz Posted February 4, 2009 Share Posted February 4, 2009 don't know if this will help but here ya go http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21050182.html Link to comment https://forums.phpfreaks.com/topic/143775-solved-setting-the-base-for-all-hrefs/#findComment-754322 Share on other sites More sharing options...
nadeemshafi9 Posted February 4, 2009 Share Posted February 4, 2009 you may also want to look into jquery Link to comment https://forums.phpfreaks.com/topic/143775-solved-setting-the-base-for-all-hrefs/#findComment-754324 Share on other sites More sharing options...
limitphp Posted February 4, 2009 Author Share Posted February 4, 2009 don't know if this will help but here ya go http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21050182.html I'm sorry, but I could not see the answer. It said something about having to statr a 7 day trial to view the solution and when I clicked on that, the site was blocked by websense here at work. Do you know what the solution said? Link to comment https://forums.phpfreaks.com/topic/143775-solved-setting-the-base-for-all-hrefs/#findComment-754337 Share on other sites More sharing options...
dennismonsewicz Posted February 4, 2009 Share Posted February 4, 2009 This is what they had on the website function getBase() { var baseTag = document.getElementsByTagName("base"); for(var i=0; i<baseTag.length; i++) { var baseId = baseTag[i].id; var baseHref = baseTag[i].href; alert("ID = "+ baseId +"\nhref = "+ baseHref); } } <body onload="getBase()"> Link to comment https://forums.phpfreaks.com/topic/143775-solved-setting-the-base-for-all-hrefs/#findComment-754343 Share on other sites More sharing options...
limitphp Posted February 4, 2009 Author Share Posted February 4, 2009 This is what they had on the website function getBase() { var baseTag = document.getElementsByTagName("base"); for(var i=0; i<baseTag.length; i++) { var baseId = baseTag[i].id; var baseHref = baseTag[i].href; alert("ID = "+ baseId +"\nhref = "+ baseHref); } } <body onload="getBase()"> on edit: ok now that I set: <base href="<?php echo SITEURL;?>"/> and I have siteurl equal to the appropriate thing, it is giving : href = http://localhost/ problem is, I could just easily set a javascript var href to <?php echo siteurl ?> thats not really what I want....because for some reason when I tell javascript (MyHttpRequest) to goto the full http://localhost address I get a : Forbidden You don't have permission to access /http://localhost/vote.php on this server. error. What I need is a way to tell the url in javascript to go up one directory. Link to comment https://forums.phpfreaks.com/topic/143775-solved-setting-the-base-for-all-hrefs/#findComment-754367 Share on other sites More sharing options...
limitphp Posted February 4, 2009 Author Share Posted February 4, 2009 Ok, I'm an idiot. It wasn't the base that was the problem. It was working, there was another completely different reason why the javascript wasn't doing what it was supposed to....it has to do with the fact that i changed how my login system works..... I used thorpe's method, and I foorgot to update this particular page.... thanks guys! Link to comment https://forums.phpfreaks.com/topic/143775-solved-setting-the-base-for-all-hrefs/#findComment-754427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.