jQuery Dialog - Dialog popup on links click

I am facing the problem of dialog not opening on subsequent click on a same link.  I read about it on different sites however I still dont know how to go about it in my case.  I have the following page http://www.clemexdownload.com/sites/newlook/test5.html
where the behavior and code can be found.  My links look something like this  <a href="images/myImage.jpg" id="imgModalX" title="My title for this image">Click to enlarge</a>
where the image uri and title is pass to the function that open the dialog.

If you have any suggestions please let me know.
Thanks
clemexAsked:
Who is Participating?
 
Sudaraka WijesingheConnect With a Mentor Web Application ProgrammerCommented:
I only experienced the problem you explained when using Chrome, it work on FF and IE.
I believe it's because after the first time image is loaded (and cached) for the session it won't fire the load() event on the second time you click the link.

Check if the code below works. (I haven't had time to test)

References:
http://api.jquery.com/live/
http://wap.w3schools.com/jsref/prop_img_complete.asp
jQuery(document).ready( function() {
 
	  
	  /* Creer images PopUp sur certain liens */
	  $("a[id^=imgModal]").click(function(event){       
			
		event.preventDefault();
		PreviewImage($(this).attr('href'),$(this).attr('title'));
											
	  });  	  
  
  //When the image has loaded, display the dialog
  $('#image').live('load', function(){
	ShowDialog();
  });

});

PreviewImage = function(uri, mytitle) {

  //Get the HTML Elements
  imageDialog = $("#dialog");
  imageTag = $('#image');
  
  //Split the URI so we can get the file name
  uriParts = uri.split("/");

  //Set the image src
  imageTag.attr('src', uri);

  if(imageTag[0].complete) ShowDialog();
}

ShowDialog = function(){

    $('#dialog').dialog({
		modal: true,
		resizable: false,
		draggable: false,
		width: 'auto',
		title: mytitle
    });
    
}

Open in new window

0
 
clemexAuthor Commented:
This is great thanks.
I modified the code slightly and it work great.  Also did not understand what the lines 12-15 were doing so   I removed them and it still work.  Are they really necessary? Maybe for a specific browser?  You can see it in action here:
http://www.clemexdownload.com/sites/newlook/test51.html

Thanks
0
 
Sudaraka WijesingheWeb Application ProgrammerCommented:
Good to know you got it working.

Lines 12-15 will not come in to play as you are using the same image in the main page and in the dialog box, because the image is already loaded by the browser in the main page before you open the dialog box.
But if you use a different image in the dialog box you will need this part of the code.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
clemexAuthor Commented:
Ok I updated this page with a different image in the dialog window but even with the bit of code it seems not to open on the first click but only on subsequent clicks.

http://www.clemexdownload.com/sites/newlook/products/powderdisperser.html

If possible you can let me know your thought on this at chabot_eric at hotmail.com
Thanks
0
 
Sudaraka WijesingheWeb Application ProgrammerCommented:
Try changing the
  //When the image has loaded, display the dialog
  $('#image').live('load', function(){
        ShowDialog();
  });

to

  //When the image has loaded, display the dialog
  $('#image').bind('load', function(){
        ShowDialog();
  });

I saw few articles when I was digging this, that live event binding seem to has a problem with load event.
0
 
clemexAuthor Commented:
Perfect!
Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.