Forum Moderators: open

Message Too Old, No Replies

How to change base href using variables.

change base href using variables

         

tommytx

9:22 pm on Dec 1, 2004 (gmt 0)

10+ Year Member



How to change base href using variables.

I need to know how to switch the base ref in mid stream and then change it back to the original after processing some area of the page.
Can it be done someway with variables like shown below?
Of course this does not work. I know if I type actual addresses into each base href, it will work but I need to do it with variables.
When I use <base href="http://www.vahud.com"> it works fine, but I need to use variables to change the ref website.

Can anyone help here?

See example below

<html>

<head>

<script>
orig="http://www.vahud.com/";
ref2="http://www.govhome4u.com/";
ref3="http://www.vahudhome4u.com/";
</script>

</head>

<body>

(This is a photo from vahud.com)<br>
<base href=orig>
<img src= "images/photo1.jpg"><br>

(This is a photo from govhome4u.com)<br>
<base href=ref2>
<img src="images/photo2.jpg"><br>

(This is a photo from vahudhome4u.com)<br>
<base href=ref3>
<img src="images/photo3.jpg"><br>

(This is a photo from vahud.com)<br>
<base href=orig>
<img src="images/photo3.jpg"><br>

</body>
</html>

RonPK

10:14 am on Dec 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script type="text/javascript"> 
function setbasehref(basehref) {
var theBase = document.getElementsByTagName("base");
theBase[0].href = basehref;
}
</script>
<base href="[full URL here]">
</head>
<body>
<script>setbasehref('[some other URL here]');</script>
<img src="...">
<script>setbasehref('[another URL here]');</script>
<img src="...">

*******
That might do the job...

tommytx

10:46 pm on Dec 5, 2004 (gmt 0)

10+ Year Member



Thanks Ron for your suggestion as I tried it with the following results.
I have included the htm I used to test it. The only photo that showed up was the last one. If I delete the last href base change, then the next one up shows up. It appears that only one base href can be applied to a page at anyone time. The last one take charge of the entire page. thanks for the help anyway.

<html>
<head>
<script type="text/javascript">

function setbasehref(basehref) {
var theBase = document.getElementsByTagName("base");
theBase[0].href = basehref;
}
</script>

<base href="http://www.hudandvahome.com/image/">

</head>

<body>

Present the first image with href set to hudandvahome.com/image/<br>
<img src="C7613.JPG"><br>

Present the second image with href set to vahud.com/vahud/images/<br>
<script>setbasehref('http://www.vahud.com/images/');</script>
<img src="lg_ball2644.jpg"><br>

Present the third image with href set to govhome4u.com/images/<br>
<script>setbasehref('http://www.govhome4u.com/images/');</script>
<img src="va_but.gif"><br>

</body>
</html>

harishkumar09

8:34 am on Dec 7, 2004 (gmt 0)

10+ Year Member



Is there anyway I can use "base href" to make all links to other external sites open in a new window while making all links that point to pages within the site open in the same window?

RonPK

8:44 am on Dec 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. Anything you specify in the base-tag, be it href or target, applies to the entire document.

kaled

9:19 am on Dec 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The base object has two properties being href and target.

I believe the base object belongs to the document, but having not used it I'm not sure. (It may belong to the window.)
Assigning the properties of this object should work.

Kaled.