Hi, I am new to JS. Long time passed trying to understand JS basics and functions...may be it's time for asking some help.
Om my exam pages I have <iframe> and <img> to change pages in the iframe. I have links to other 5 pages that are opened in the <iframe>. I decide to coppy all my files to 2 directories: "english" and "bulgarian" and to create a function wich search URL of the iframe.
IE7, Maxthon and Opera handle it well and alter my last page in the iframe, but Firefox not. Here is my code:
function changeLang() // related to <img ... lang_btn & lang_btn_f2 onclick event .. change content in <iframe> element
{
var agt=navigator.userAgent.toLowerCase(); // 1 st part of function is trying to determine if browser is Firefox (because of problems when loaded with firefox)
if (agt.indexOf("firefox") != -1)
{
var add = document.getElementById('content').src;
if (add.indexOf("english") != -1)
{
add = add.replace("english","bulgarian");
document.getElementById('content').src = add;
}
else if (add.indexOf("bulgarian") != -1)
{
add = add.replace("bulgarian","english");
document.getElementById('content').src = add;
}
}
// end of firefox code block
else
{
var add = frames['content'].location.href; //second part of code that works fine with IE, Maxthon and Opera
if (add.indexOf("english") != -1)
{
add = add.replace("english","bulgarian");
frames['content'].location.href = add;
}
else if (add.indexOf("bulgarian") != -1)
{
add = add.replace("bulgarian","english");
frames['content'].location.href = add;
}
}
} //end of changeLang() function
function roll_over(action, img_name, img_src, cursor) // this function handles altering images for appropriate page languages and mouse events
{
var agt=navigator.userAgent.toLowerCase(); // part 1 : firefox
if (agt.indexOf("firefox") != -1)
{
var add = document.getElementById('content').src;
if (add.indexOf("english") != -1)
{
if(action == "over")
{
img_src = "images/lang_btn.jpg";
}
if(action == "out")
{
img_src = "images/lang_btn_f2.jpg";
}
}
else if (add.indexOf("bulgarian") != -1)
{
if(action == "over")
{
img_src = "images/lang_btn_f2.jpg";
}
if(action == "out")
{
img_src = "images/lang_btn.jpg";
}
}
document[img_name].src = img_src;
document.getElementById(img_name).style.cursor = cursor;
} //end of firefox part
else
{
var add = frames['content'].location.href; //part 2 - works with IE, Maxthon and Opera
if (add.indexOf("english") != -1)
{
if(action == "over")
{
img_src = "images/lang_btn.jpg";
}
if(action == "out")
{
img_src = "images/lang_btn_f2.jpg";
}
}
else if (add.indexOf("bulgarian") != -1)
{
if(action == "over")
{
img_src = "images/lang_btn_f2.jpg";
}
if(action == "out")
{
img_src = "images/lang_btn.jpg";
}
}
document[img_name].src = img_src;
document.getElementById(img_name).style.cursor = cursor;
}
} // script ends here
I'm sure that doing something wrong but don't know where my misstakes are especially about Firefox. Excuse me for the long code, but my experience is really poor.