PDA

View Full Version : Crossbrowser use of JS FN as url


Xmo1
09-02-2002, 05:28 AM
I've been writing for MSIE using JS Functions as URL's
<a href="javascript: openhome()">Openhome</a>
which don't work in NetScape. Notice the site is in frames. Most url function calls update two frames. The code is in a file named selector.js located at root, and is accessed using relative references from pages located in a multilevel directory structure. What would be the best solution to get cross browser compatibility? Here's part of my code:

/*get frameset by resolution*/
function openhome() {
var hw
var fname
hw=screen.width
if (hw < 900) {
fname = "/bindex.htm"
} else {
fname = "/aindex.htm"
}top.location.href = fname
}
/* menu */
function opensection() {
parent.frames["content"].location.href = "/section/s-one.htm";
parent.frames["rightmenu"].location.href = "/section/s-right.htm"
}
function openlinks() {
parent.frames["content"].location.href = "/section/business/sb-hrlinks.htm";
parent.frames["rightmenu"].location.href = "/section/business/sb-right.htm"
}

joh6nn
09-02-2002, 07:14 AM
cross frame referencing isn't cross browser compatible. one browser bases references off the current frame, and one browser bases them off the other frame. i forget which does which. the only work around, is absolute urls. eg,

function opensection() {
parent.frames["content"].location.href = "http://www.whatever.com/section/s-one.htm";
parent.frames["rightmenu"].location.href = "http://www.whatever.com/section/s-right.htm"
}

Xmo1
09-02-2002, 12:15 PM
Might be true. I'll try it, but I think the problem is that netscape doesn't recognize js functions in the url portion of an anchor .

joh6nn
09-02-2002, 12:34 PM
i can guarentee you that that's not the case.

brothercake
09-02-2002, 12:40 PM
I can - the javascript: pseduo protocol is utterly cross-browser. I guarante that is not the cause of your problem.

btw though, you shouldn't have spaces. It should be

<a href="javascript:openhome()">Openhome</a>

Xmo1
09-02-2002, 02:03 PM
I don't have spaces in the code. Something about message board parsing probably. <no mas>

I changed to absolute addressing and it worked. The closest I get to NetScape is Mozilla 1.0 Thanks, I've been trying to fix the problem for a long time without recoding the whole site. Very grateful. Thanks again.