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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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()"> Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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.