...

View Full Version : Two scripts conflicting ?



waps2
07-24-2011, 07:53 PM
Hi guys I have to scripts on my page and they work fine on their own but when i put them together one stops working ??

One is the colorbox script and the other toggles some hidden content.

Any ideas why they wont work on the same page ?

This is whats in my head section and the start of the body section



<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="../../js_files/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="../../js_files/jquery.tools.min.js"></script>
<!--[if lt IE9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" href="../../colorbox/colorbox.css" type="text/css" />
<script src="http://code.jquery.com/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="../../colorbox/jquery.colorbox-min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
//Examples of how to assign the ColorBox event to elements
$("a[rel='slides']").colorbox({transition:"none", width:"70%", height:"70%", scalePhotos:false});
});
</script>
</head>

<body>
<script language="JavaScript" type="text/javascript">
$(function() {
$("#tabs").tabs("#tabscontent section", {
effect: 'fade',
fadeOutSpeed: 0,
fadeInSpeed: 400
});
});
</script>

Philip M
07-24-2011, 08:11 PM
This question has been asked and answered a zillion times in this forum.

There are two basic reasons why scripts will not work together.

a) duplication of function and/or variable names between the scripts - the second will over-write the first.
b) multiple onload statements.
See:- http://www.javascriptkit.com/javatut...iplejava.shtml
http://www.dyn-web.com/tutorials/combine.php


"It's so simple to be wise. Just think of something stupid to say and say the opposite." - Sam Levenson

waps2
07-24-2011, 08:48 PM
Hi,

Thanks for your help.

Would it work if i wrapped both the code snipets there in a new function and then called both those functions from the body onload call ?

:confused:

Philip M
07-24-2011, 08:51 PM
Hi,

Thanks for your help.

Would it work if i wrapped both the code snipets there in a new function and then called both those functions from the body onload call ?

:confused:

Assuming that the trouble is multiple onloads, then you can use

<script type="text/javascript">
window.onload = function() {
functionOne();
functionTwo();
}
</script>

waps2
07-24-2011, 09:27 PM
Hi Philip

Thanks for helping me. I tried that method but doesnt appear to want to work.

So must be another problem. Conflist of function name maybe like you suggested ?

I have no idea where to start though on this one :confused:

waps2
07-24-2011, 09:53 PM
Hi,

Not to worry I figured it out now yay lol :)

It was a function name conflict and also I was trying to include two jquery library files.

:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum