Daybreak0
12-30-2009, 10:54 PM
Hi I am using a generic Template in a site where different domain names may enter at different levels of a web site.
By using some CSS in my <header> to set the base url.
<base href="http://www.MyDomain.com">
I am able to refer to the address of an image by just having
<img src= "/images/photo1.jpg">
which will display the image
http://www.MyDomain.com/images/photo1.jpg
By changing the BASE URL I am able to change which image will display.
So I need to obtain the URL address that the viewer, came into the web site on, and then set the BASE URL.
I have managed to find the following code
This code obtains the URL (placed in the header)
<script type="text/javascript"> function writeDomain()
{ var myDomain = document.domain; document.write(myDomain);}</script>
and this code would write the URL address in the body
<script type="text/javascript">writeDomain()</script>
Then I found the following script which actually sets the BASE URL.
<script type="text/javascript">
function setbasehref(basehref) {
var thebase = document.getElementsByTagName("base");
thebase[0].href = basehref;
} </script>
and then the following call which would be used to actually set the BASE Url.
<script>setbasehref('http://www.mydomain.com/');</script>
So I thought- I have the code to egt the URL and I have the code to set the BASE URL, will this work -
<script>setbasehref(writeDomain());</script>
Which just goes to show I have no Javascript knowledge at all.
As per above I am trying to retrieve the current URL and then set the BASE URL to Current URL.
There maybe even a simpler way to write it than the convulted adding together, but any help appreciated.
Thank you
John
By using some CSS in my <header> to set the base url.
<base href="http://www.MyDomain.com">
I am able to refer to the address of an image by just having
<img src= "/images/photo1.jpg">
which will display the image
http://www.MyDomain.com/images/photo1.jpg
By changing the BASE URL I am able to change which image will display.
So I need to obtain the URL address that the viewer, came into the web site on, and then set the BASE URL.
I have managed to find the following code
This code obtains the URL (placed in the header)
<script type="text/javascript"> function writeDomain()
{ var myDomain = document.domain; document.write(myDomain);}</script>
and this code would write the URL address in the body
<script type="text/javascript">writeDomain()</script>
Then I found the following script which actually sets the BASE URL.
<script type="text/javascript">
function setbasehref(basehref) {
var thebase = document.getElementsByTagName("base");
thebase[0].href = basehref;
} </script>
and then the following call which would be used to actually set the BASE Url.
<script>setbasehref('http://www.mydomain.com/');</script>
So I thought- I have the code to egt the URL and I have the code to set the BASE URL, will this work -
<script>setbasehref(writeDomain());</script>
Which just goes to show I have no Javascript knowledge at all.
As per above I am trying to retrieve the current URL and then set the BASE URL to Current URL.
There maybe even a simpler way to write it than the convulted adding together, but any help appreciated.
Thank you
John