PDA

View Full Version : Conflicting javascripts



ARDR
03-17-2006, 07:52 PM
I've got a question. To load a PHP document in an iframe I used the SSI III script which John has posted in this forum see this tread (http://www.dynamicdrive.com/forums/showthread.php?t=5060&page=2).
After adjusting a few things, which John suggested, the script works fine.

But I already had a script, placed in an external scriptfile which makes mouseover buttons whith a sound. After inserting the SSI III script the mouseover buttons stopped working.

Here's a link to the webpage i'm mentioning:
http://www.drenthe-dakar.nl/voorbereiding.htm

Here's the code of the buttons:

// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
if (document.images) {
// Rollover images
team = new Image();
team.src = "buttons/team.png";
team2 = new Image();
team2.src = "buttons/team2.png";
auto = new Image();
auto.src = "buttons/auto.png";
auto2 = new Image();
auto2.src = "buttons/auto2.png";
}
function OnImage(name) {
if (document.images) {
fullname = eval(name + "2");
document[name].src = fullname.src;
}}
function OffImage(name) {
if (document.images) {
fullname = eval(name);
if (fullname.complete) {
document[name].src = fullname.src;

}}}
var agt=navigator.userAgent.toLowerCase();
var is_major=parseInt(navigator.appVersion);
var is_minor=parseFloat(navigator.appVersion);
var is_nav=((agt.indexOf('mozilla')!=-1)&&(agt.indexOf('spoofer')==-1)&&(agt.indexOf('compatible')==-1)&&(agt.indexOf('opera')==-1)&&(agt.indexOf('webtv')==-1));
var is_ie=(agt.indexOf('msie')!=-1);
if(is_ie){
var agt_ie=agt.substring(agt.indexOf('msie')+5); is_major=parseInt(agt_ie); is_minor=parseFloat(agt_ie);
}
var is_dom2=(document.getElementById);
function jsStop( o )
{
if(is_ie&&is_major>=4&&eval('document.'+o)){var e=eval('document.'+o);
if(e.src&&e.src!=''&&e.ReadyState&&e.ReadyState>=4){e.stop();
}}
else
{
if(is_nav&&is_major>=3&&(is_major<4||eval('document.'+o))){eval('document.'+o+'.stop()');
}}}
function jsPlay( o )
{
if(is_ie&&is_major>=4&&eval('document.'+o))
{
var e=eval('document.'+o);
if(e.src&&e.src!=''&&e.ReadyState&&e.ReadyState>=4)
{
if (is_major>=5){e.play();
}
else
{
e.run();
}}}
else{
if(is_nav&&is_major>=3&&(is_major<4||eval('document.'+o))){eval('document.'+o+'.play(false)');
}}}


This is the adjusted code of the SSI III script


///script iframe
/***********************************************
* IFrame SSI script III- &#169; jscheuer1 (http://www.dynamicdrive.com/forums)
* very loosely based upon IFrame SSI script II- &#169; DynamicDrive
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Set optional Mozilla (recent FF, NS and other Mozilla based browsers)
//height adjustment if needed for your layout to avoid scrollbars.
//example: var mAdjust=14
var mAdjust=42
//////////////////No Need To Edit Below Here////////////////////

function collectWidth(obj){
var wVal=0
var objs=obj.document.getElementsByTagName('*')
for (var i_tem = 0; i_tem < objs.length; i_tem++){
wVal=Math.max(objs[i_tem].offsetWidth, wVal)
}
return wVal;
}

function setClicks(obj){
var links=obj.contentDocument.getElementsByTagName('a')
var iFrameObjs=document.getElementsByTagName('iframe')
for (var i_tem = 0; i_tem < links.length; i_tem++){
for (var j_tem = 0; j_tem < iFrameObjs.length; j_tem++)
if (links[i_tem].target==iFrameObjs[j_tem].name)
links[i_tem].onclick=new Function('parent.'+links[i_tem].target+'.location.replace(this.href);return false;')
else if (links[i_tem].target!=='')
links[i_tem].target=links[i_tem].target
else
links[i_tem].onclick=new Function('parent.'+obj.name+'.location.replace(this.href);return false;')
}
links=document.getElementsByTagName('a')
for (i_tem = 0; i_tem < links.length; i_tem++){
for (j_tem = 0; j_tem < iFrameObjs.length; j_tem++)
if (links[i_tem].target==iFrameObjs[j_tem].name)
links[i_tem].onclick=new Function('window.'+links[i_tem].target+'.location.replace(this.href);return false;')
}
}

function sizeFrame(frameObj){
if ((frameObj.contentDocument && (frameObj.contentDocument.body.offsetHeight||frameObj.contentDocument.documentElement.offsetHeight))||frameObj.Document && frameObj.Document.body.scrollHeight){
if (window.opera)
setClicks(frameObj)
var contentHeight=window.opera? frameObj.contentDocument.documentElement.offsetHeight : frameObj.contentDocument? frameObj.contentDocument.body.offsetHeight+mAdjust : frameObj.Document.body.scrollHeight+4
var contentWidth=window.opera? collectWidth(frameObj.contentDocument) : frameObj.contentDocument? frameObj.contentDocument.documentElement.offsetWidth : frameObj.Document.body.scrollWidth
var frameWidth=frameObj.offsetWidth
if(!window.opera)
frameObj.style.overflow='visible'
frameObj.height = frameWidth<contentWidth? contentHeight+18 : contentHeight+3;
if (window.opera&&frameWidth>=contentWidth)
frameObj.contentDocument.body.style.overflow='hidden'
}
}

As you can see, I'm not very into javascript and are using codes of others. I really appreciate people who want to help others in this way.

Does someone know what is conflicting in these two scripts?

Thanks!

simonf
03-18-2006, 08:04 AM
Hi

Take a look at number of scripts a page can contain (http://www.javascriptkit.com/javatutors/multiplejava2.shtml)

ARDR
03-20-2006, 06:30 PM
Thanks, I solved the problem, however the scripts weren't conflicting, but I made a small mistake linking the external scriptfile..
:D Oops, I will not screem again before I'm bitten (Dutch expression)

But I learned a valueable lesson about javascripting.