Jump to content

[SOLVED] Setting the Base for All hrefs?


limitphp

Recommended Posts

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

 

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?

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()">

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.