Entry
How to get <Base href=> to work for relative links inside a javascript with IE. It works with NN.
Apr 7th, 2008 23:33
ha mo, Colin Fraser, jellether moore,
I understand that this is in fact a long standing problem with earlier
versions of Netscape and most versions of IE, I am not sure about the
most recent versions of either, but you say you have it working in
Netscape but not IE. As a general rule of thumb, my approach has been to
use script to control essential navigation, not HTML. I prefer to use
something along the lines of:
<script>
function goingto(newLoc) {
location.href= newLoc
}
</script>
and
<a href="javascript:"goingto('thispage.htm')">This Page</a>
However, I have also managed to avoid using the <base href=... by using
the frames array. Here is some old code I use to use for a set of
tutorials I wrote a long time ago...
The first array is the pages I wanted to display
pageArray = new Array("tute1.htm", "tute2.htm", "tute3.htm",
"tute4.htm", "tute5.htm", "tute6.htm", "tute7.htm" );
Later I added a bit more diversity different menus, I had to create a
menu array to work in conjunction with the page array
menuArray = new Array("menu.htm", "menu2.htm", "menu3.htm", "menu4.htm",
"menu5.htm", "menu6.htm", "menu7.htm" );
This function used the frames array to set the visible document in the
main frame
function set1Frame(newPage) {
parent.frames[1].document.location.href = pageArray[newPage];
}
After creating the menu array, I added another line to the code linking
menus and pages, as the main page changed so did the menu.
function set2Frames(newMenu,newPage) {
parent.frames[0].document.location.href = menuArray[newMenu];
parent.frames[1].document.location.href = pageArray[newPage];
}
In the menu page I used this code:
<a href="javascript:set1Frame(0)">Tutorial 1.</a> <br>
and repeated it for each page I wanted to change via the page array.
Later I used this code :
<a href="javascript:set2Frames(1,1)">Tutorial 2.</a><br>
This one I send 2 variables to the function that accesses the page and
menu arrays.
In both these cases I have avoided using <base href= as at that time it
was more trouble than it was worth. I am not sure why the problem
existed but it did. Today, I use a cleaner form navigation to get where
I want to go, like :
The form:
<form>A Navigation Menu
<select name="nextLoc" onChange="goPage(this.form.nextLoc)">
<option value="" SELECTED>Select a topic
<option value="http://www.artworks.com">Art Works
<option value="tute1.htm">Object D'Art
<option value="tute2.htm">Secure handling
</form>
The function :
function goPage(newLoc) {
if (newLoc.options[newLoc.selectedIndex].value != "") {
location.href= newLoc.options[newLoc.selectedIndex].value
} //if
else {
alert("Please select another topic")
}
}
I have seen variations on this code but it works nonetheless in any
situation. As long as you pass the correct URL, you have no need to use
<base href=
I hope this answers your question, and maybe offers an alternative that
works for you. Good luck.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com