开发者

Jquery/Javascript conflicts?

I just implemented a multi-language mod onto my website.

Problem is that there seems to be a conflict between the javascript files from the language mod and the javascript files that alread开发者_如何学编程y were on the page.

<!-- language files here -->
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/translationEngine.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script> 
<script type="text/javascript" src="js/jquery.translate-1.3.9.min.js"></script>
<script>var browserlang = 'en';</script> 


<!-- Javascript -->

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.pngFix.pack.js"></script>
<script type="text/javascript" src="js/jquery.flow.1.2.min.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="js/concept.js"></script>

js/jquery-1.3.2.min.js is what makes the 3 image slider on the homepage work, but... it seems to also be interfering with the functions of the translator.

If u remove js/jquery-1.3.2.min.js from the page, the translator works fine, but the slider no longer works.

removing js/jquery-1.4.2.min.js from the page doesnt make the translator work either, in fact it seems to cause more errors in the back.

Can someone guide me in the right direction that would allow me to make the language translator and image slider both work?

http://filefx.com

Thanks :)


The short version is to remove this:

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

And update your plugins, there are likely 1.4.x versions out there for each of them. By including jQuery a second time, like you are currently, it'll wipe out plugins and cause all sorts of issues...the first step is removing the second (hopefully the older) instance.

Edit: Here's an updated version of jFlow called jFlow plus that works with 1.4.2.


Check out the jQuery noConflict function. This function tells jQuery to relinquish it's control over the $ variable. This way, other libraries can use it.

The online docs give a pretty good guide as to how to use this function. It saved me a few times.

Example from the online docs:

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>

Basically, once you call noConflict, you can still use jQuery, just use it using the jQuery variable name instead of $.

Hope this helps!


I have alway solved conflicts between two versions of jquery e.g. jQuery 1.3.2 and jQuery 1.4.2 on the same page using iframes but i recently found out that you can use version jquery-1.5.1.js alone and everything works fine.


I change all the .js file on the page used from below code:

<script>
var K = jQuery.noConflict();
     alert(K);
     jQuery(document).ready(function () {

         alert("Bye");
     });
</script>

It works fine now.


I ended up just changing the order in which the libraries loaded.

I let all the jquery libraries load first, from newest to oldest. Then i called for the javascript files that rely on jquery.

It works fine now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜