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
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?

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.