Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Two JavaScript clash ???

  1. #1
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Unhappy Two JavaScript clash ???

    Hello,
    i was going to use combine two tutorial in my site. 1st one is a tooltip & other one is a newsticker.
    this is the tooltip that i have used http://flowplayer.org/tools/demos/tooltip/index.htm

    then i integrated the the newsticker's(attachment) JavaScript also(jquery-1.3.2.min.js). but when it integrated the tooltip was not working, even just put in to web page like bellow,
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    	<title>Test</title>
    	
    	<link rel="stylesheet" type="text/css" href="css/standalone.css">		<!-- css of tooltip -->
    	<script  type="text/javascript" src="js/jquery.js"></script>			<!-- js of tooltip -->		
    	<script  type="text/javascript" src="js/jquery-1.3.2.min.js"></script>	<!-- js of newsticker -->
    
    etc............
    i have attached the problematic js also. Is this a clash ??? please can any one tell me how can I neglect this problem ???

    thank you

  2. #2
    Join Date
    Apr 2010
    Posts
    33
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default

    When you include 2 jQuery @ once, it could be the conflict.

  3. #3
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default

    thanx sanduwa for your response.
    would you tell me why can't include two jquerys? is it impossible ??? even isn't there any single way to include two jquerys ???

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    jQuery is a library of routines. You only need one. To fix that, replace:

    Code:
    	<link rel="stylesheet" type="text/css" href="css/standalone.css">		<!-- css of tooltip -->
    	<script  type="text/javascript" src="js/jquery.js"></script>			<!-- js of tooltip -->		
    	<script  type="text/javascript" src="js/jquery-1.3.2.min.js"></script>	<!-- js of newsticker -->
    with:

    Code:
    	<link rel="stylesheet" type="text/css" href="css/standalone.css">		<!-- css of tooltip -->
    	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    If that doesn't fix it, there might be a conflict between the ticker and tip scripts. To find out, we would need a link to your page.

    If you want more help:

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default

    Thank you for responding me jscheuer1,
    it's also not working by using
    Code:
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    this is the Tooltip http://shmtestforums.uphero.com/Test...p/Tooltip.html

    this is the newsticker http://shmtestforums.uphero.com/Test...ewsticker.html

    & this is the combination of there two http://shmtestforums.uphero.com/Testing/test/test.html

    here you can see tooltips are working but not newsticker. please help me jscheuer1. thanx again.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The problem isn't as we first thought, two jQuery scripts. On the shmtestforums.uphero.com/Testing/test/test.html page, it's one jQuery script and one mootools script - a conflict between two script libraries, both of which want control of the $ variable. On that page you can fix things by changing:

    Code:
    <script type="text/javascript">
    $(document).ready(function(){
    	
    	var speed = 700;
    	var pause = 3500;
    	
    	function newsticker()
    	{
    	    last = $('ul#listticker li:last').hide().remove();
    	    $('ul#listticker').prepend(last);
            $('ul#listticker li:first').slideDown("slow");
    	}
    	
    	interval = setInterval(newsticker, pause);
    });
    </script>
    to (change highlighted):

    Code:
    <script type="text/javascript">
    jQuery(function($){
    	
    	var speed = 700;
    	var pause = 3500;
    	
    	function newsticker()
    	{
    	    last = $('ul#listticker li:last').hide().remove();
    	    $('ul#listticker').prepend(last);
            $('ul#listticker li:first').slideDown("slow");
    	}
    	
    	interval = setInterval(newsticker, pause);
    });
    </script>
    Note: The order that the scripts in the head are in is important. Fortunately you already have them in the correct order on that page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. The Following User Says Thank You to jscheuer1 For This Useful Post:

    M rosi (09-09-2010)

  8. #7
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default

    This is an amazing work jscheuer1 thank you very much.
    actually this is unbelievable.
    but how can we know what is the order of the jquerys? is there any method to understand it?
    if i want to combine a another jquery(3rd jquery) to this what should be the order? lets take an eg,
    this is a jquery for rotating billboard system,
    Code:
    <head>
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="jqFancyTransitions.1.8.min.js"></script>
    </head>
    <body>
    	<div id="slideshowHolder">
    		<img src="1.jpg"/>
    		<img src="2.jpg"/>
    		<img src="3.jpg"/>			 
    		<img src="4.jpg"/>
    		<img src="5.jpg"/>
    	</div>
    		<script type="text/javascript" src="jquery.js"></script>
    </body>
    so what would be the order. please jscheuer1 tell me how the order can be understand ???

    however big thanx John

  9. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There are two main considerations:

    1. jQuery is the only script library I know of that can coexist with another.

    2. The easiest way for it to do so is to come first, do its work, then hand over control to the other library.


    This depends upon another consideration - upon how well the script(s) that use jQuery are written.

    I think you may or may not be missing an important point here, so it bears emphasis:

    jQuery and mootools are script libraries (there are many, like dojo and prototype to name only two others). None of them do much in and of themselves other than set up a large variety of routines for accomplishing various tasks more simply than can be done with javascript alone. For some reason though, the authors of each of these libraries have chosen the variable $ to be the cornerstone of their library. And they all use it in different ways. jQuery alone (as far as I know) has several established methods to allow it and the code that uses it to do its work with $ and then hand that variable over to another library. But for this to work with any given script written for jQuery, the author of that script has to have taken advantage of at least one of these several methods I just alluded to.

    Additionally, if you have an external script tag on your page to jQuery (or one to any other script library), like (in this case jQuery):

    Code:
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
    as long as things are arranged properly, you shouldn't need another one to jQuery. If it's another script library, you shouldn't need another one to that library. Each library only needs to, and generally only should be included once on any one page. The one exception is if for some reason you need to run two or more different versions of the jQuery library on the same page. In which case you can do so, provided the code of the scripts using each jQuery version is well written and you take the proper steps to allow each version of jQuery and the scripts that use each one control of the $ variable when they need it. Generally though any script that uses jQuery can be made to work with any version of jQuery with little or no modification. So this situation isn't as common as one might think.

    Hopefully that clears some things up if only in a general sort of way.

    Now, about your question - as long as the jqFancyTransitions script is well enough written visa vis taking advantage of one of the techniques that allows it to work with other libraries, you can do this (addition highlighted):

    Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Test Combine</title>
    <link rel="stylesheet" type="text/css" href="css/standalonenewsticker.css">
    <link rel="stylesheet" type="text/css" href="css/standaloneTooltip.css">
    
    
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    
    <script type="text/javascript">
    jQuery(function($){
    	
    	var speed = 700;
    	var pause = 3500;
    	
    	function newsticker()
    	{
    	    last = $('ul#listticker li:last').hide().remove();
    	    $('ul#listticker').prepend(last);
            $('ul#listticker li:first').slideDown("slow");
    	}
    	
    	interval = setInterval(newsticker, pause);
    });
    </script>
    <script type="text/javascript" src="jqFancyTransitions.1.8.min.js"></script>
    <script src="js/mootools.js" type="text/javascript"></script>
    
    <script type="text/javascript" charset="utf-8">
    window.addEvent('domready', function() {
    	
    	// Create variables (in this case two arrays) representing our bubbles and pages
    	var myPages = $$('.page');
    	var myBubbles = $$('.bubble');
    	
    	// Set bubbles opacity to zero so they're hidden initially and toggle visibility on for their container	
    	myBubbles.setStyle('opacity', 0);
    	$('bubbleWrap').setStyle('visibility','visible')
    	
    	// Add our events to the pages
    	myPages.each(function(el, i) {
    		el.set('morph', {link : 'cancel'});
    		
    		el.addEvents({
    			'mouseenter': function() {
    				myBubbles[i].morph({
    					'opacity' : 1,
    					'margin-top' : '-15px'
    				});
    			},
    			'mouseleave' : function() {
    				myBubbles[i].morph({
    					'opacity' : 0,
    					'margin-top' : 0
    				});
    			}	
    		});
    	});
    });
    
    </script>
    </head>
    Notice that the:

    Code:
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    tag for the jQuery library appears only once on the page and that both scripts that use it (newsticker, which is an on page script, and jqFancyTransitions, which is an external script) appear before the:

    Code:
    <script src="js/mootools.js" type="text/javascript"></script>
    tag that brings in the mootools library.

    As I say, if jqFancyTransitions is well enough written as far as the ability to coexist goes, it will work just like that and you may place:

    HTML Code:
    	<div id="slideshowHolder">
    		<img src="1.jpg"/>
    		<img src="2.jpg"/>
    		<img src="3.jpg"/>			 
    		<img src="4.jpg"/>
    		<img src="5.jpg"/>
    	</div>
    anywhere in the body of the page you want this feature to appear.

    One thing that troubles me is that you have after that:

    Code:
    <script type="text/javascript" src="jquery.js"></script>
    If this is what it appears to be - another external script tag to jQuery, it can simply be skipped. If it's to another helper script (like an initialization) for the jqFancyTransitions, it will need to be kept, and hopefully it is written in such a way that it can work given all the other scripts before it on the page.

    To be more specific I would need to see a working example (on a page by itself if need be) of jqFancyTransitions running this slideshow.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. The Following User Says Thank You to jscheuer1 For This Useful Post:

    M rosi (09-09-2010)

  11. #9
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default

    wow what an explanation! thank you very much.
    you are encouraging me lot to learn jQuery.

    In the last example is very tough.may it has little mistake.
    http://shmtestforums.uphero.com/rota...rd/rotate.html

    Thanx lot John.

  12. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Turns out this:

    Code:
    <body>
    
    
    	<div id="slideshowHolder">
    		<img src="1.jpg"/>
    		<img src="2.jpg"/>
    		<img src="3.jpg"/>			 
    		<img src="4.jpg"/>
    		<img src="5.jpg"/>
    
    	</div>
    		<script type="text/javascript" src="jquery.js"></script>
    Is not a link to jQuery. It's to this script:

    Code:
    		$('#slideshowHolder').jqFancyTransitions({ position: 'curtain' });
    
    		$('#effCurtainAlternate').click( function(){
    			$('#slideshowHolder').jqFancyTransitions({ position: 'curtain', direction: 'alternate' });
    			$('#positionDyn').html('curtain');
    			$('#directionDyn').html('alternate');
    		});
    
    		$('#effFountainTop').click( function(){
    			$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    			$('#slideshowHolder').jqFancyTransitions({ position: 'top', direction: 'fountain' });
    			$('#positionDyn').html('top');
    			$('#directionDyn').html('fountain');
    		});	
    
    		$('#effRandomTop').click( function(){
    			$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    			$('#slideshowHolder').jqFancyTransitions({ position: 'top', direction: 'random' });
    			$('#positionDyn').html('random');
    			$('#directionDyn').html('top');
    		});	
    
    		$('#effLeftTop').click( function(){
    			$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    			$('#slideshowHolder').jqFancyTransitions({ position: 'top', direction: 'left' });
    			$('#positionDyn').html('left');
    			$('#directionDyn').html('top');
    		});	
    
    		$('#effRightBottom').click( function(){
    			$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    			$('#slideshowHolder').jqFancyTransitions({ position: 'bottom', direction: 'right' });
    			$('#positionDyn').html('right');
    			$('#directionDyn').html('bottom');
    		});			
    
    		$('.eComb').click( function(){
    			$('#eComb').show();
    			$('#eEff').hide();
    			$('.eComb').removeClass('slideshowHolderActive');
    			$('.eEff').removeClass('slideshowHolderActive');			
    			$(this).addClass('slideshowHolderActive');
    		});	
    
    		$('.eEff').click( function(){
    			$('#eComb').hide();
    			$('#eEff').show();
    			$('.eEff').removeClass('slideshowHolderActive');
    			$('.eComb').removeClass('slideshowHolderActive');			
    			$(this).addClass('slideshowHolderActive');			
    		});	
    
    		$('#effWave').click( function(){
    			$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    			$('#slideshowHolder').jqFancyTransitions({ effect: 'wave' });
    			$('#effDyn').html('wave');
    		});		
    
    		$('#effZipper').click( function(){
    			$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    			$('#slideshowHolder').jqFancyTransitions({ effect: 'zipper' });
    			$('#effDyn').html('zipper');
    		});		
    
    		$('#effCurtain').click( function(){
    			$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    			$('#slideshowHolder').jqFancyTransitions({ effect: 'curtain' });
    			$('#effDyn').html('curtain');
    		});
    Looking at everything else, this (the above script) appears to be the only place where the $ is exposed in such a way that, if another library like mootools is on the page, it won't be able to use the jQuery meaning for $. This can be fixed by adding to the above code (wrapping it in an anonymous function that defines jQuery for it locally), so that it looks like so (additions highlighted, one top, one bottom):

    Code:
    (function($){
    	$('#slideshowHolder').jqFancyTransitions({ position: 'curtain' });
    
    	$('#effCurtainAlternate').click( function(){
    		$('#slideshowHolder').jqFancyTransitions({ position: 'curtain', direction: 'alternate' });
    		$('#positionDyn').html('curtain');
    		$('#directionDyn').html('alternate');
    	});
    
    	$('#effFountainTop').click( function(){
    		$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    		$('#slideshowHolder').jqFancyTransitions({ position: 'top', direction: 'fountain' });
    		$('#positionDyn').html('top');
    		$('#directionDyn').html('fountain');
    	});	
    
    	$('#effRandomTop').click( function(){
    		$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    		$('#slideshowHolder').jqFancyTransitions({ position: 'top', direction: 'random' });
    		$('#positionDyn').html('random');
    		$('#directionDyn').html('top');
    	});	
    
    	$('#effLeftTop').click( function(){
    		$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    		$('#slideshowHolder').jqFancyTransitions({ position: 'top', direction: 'left' });
    		$('#positionDyn').html('left');
    		$('#directionDyn').html('top');
    	});	
    
    	$('#effRightBottom').click( function(){
    		$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    		$('#slideshowHolder').jqFancyTransitions({ position: 'bottom', direction: 'right' });
    		$('#positionDyn').html('right');
    		$('#directionDyn').html('bottom');
    	});			
    
    	$('.eComb').click( function(){
    		$('#eComb').show();
    		$('#eEff').hide();
    		$('.eComb').removeClass('slideshowHolderActive');
    		$('.eEff').removeClass('slideshowHolderActive');			
    		$(this).addClass('slideshowHolderActive');
    	});	
    
    	$('.eEff').click( function(){
    		$('#eComb').hide();
    		$('#eEff').show();
    		$('.eEff').removeClass('slideshowHolderActive');
    		$('.eComb').removeClass('slideshowHolderActive');			
    		$(this).addClass('slideshowHolderActive');			
    	});	
    
    	$('#effWave').click( function(){
    		$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    		$('#slideshowHolder').jqFancyTransitions({ effect: 'wave' });
    		$('#effDyn').html('wave');
    	});		
    
    	$('#effZipper').click( function(){
    		$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    		$('#slideshowHolder').jqFancyTransitions({ effect: 'zipper' });
    		$('#effDyn').html('zipper');
    	});		
    
    	$('#effCurtain').click( function(){
    		$('#ft-title-slideshowHolder, .ft-slideshowHolder').remove();
    		$('#slideshowHolder').jqFancyTransitions({ effect: 'curtain' });
    		$('#effDyn').html('curtain');
    	});	
    })(jQuery);
    But the page (shmtestforums.uphero.com/rotating_billboard/rotate.html) isn't using most of that. So you could use simply:

    Code:
    jQuery('#slideshowHolder').jqFancyTransitions({ position: 'curtain' });
    Once you change the code in the file referred to by:

    Code:
    <script type="text/javascript" src="jquery.js"></script>
    to either of the two scripts blocks above suggested for it, the instructions from my previous post as to how to arrange things in the head should work. I couldn't easily test it though because you've apparently moved/removed the resource files from the previous demo.

    If you want more help getting the three working together, put up a demo like the one that was at shmtestforums.uphero.com/Testing/test/test.html that attempts to use all three scrpts.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •