Question

I update this once again, this only fails in some versions of IE. It's something with the last line in the js code. "$($nextlink).trigger('click');" that some versions of IE can't handle... Is it possible to do a work around that will make sure it works in all IE versions?

Here is the javascript...

$(".trigger").live('click',function() {
 if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } // to prevent default link to image, event.returnValue = false; for it to work in IE.
    var $currentId =$(this).attr('id'); //The Id of the clicked thumbnail
    var $newlink = $currentId + '.php'; //The new images in a .php file
    var $newcontent = '#' + $currentId + 'box'; //Where to load
    var $nextlink = '#' + $(this).next().attr('id'); //The simulated click id
    $($newcontent).load($newlink, function() {
    $("a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'fast',theme:'light_square',slideshow:3000, autoplay_slideshow: false, hideflash: true, deeplinking:false});
$($nextlink).trigger('click');
    });
});

Html:

<li class="projectitem photo" data-id="id-1">
<div class="grid_1 projectbox">
<div class="boxcontain surf">
<a id="surf" class="trigger" href="img/_MG_8635.jpg"><img class="fade" src="img/thumb_surfbw.jpg" title="Surfing" style="background: url(img/thumb_surfcolor.jpg);" alt="Surfing" /></a>
<a id="surflink" class="hide" rel="prettyPhoto[surfing]" href="img/_MG_8635.jpg" title='<strong>Project: </strong>Photo gallery of my selected surf photos from Hawaii<br><strong>Year: </strong>2011<br><strong>Type: </strong>Photo'><img class="fade" src="img/thumb_surfbw.jpg" title="Surfing" style="background: url(img/thumb_surfcolor.jpg);" alt="Surfing" /></a>
<div id="surfbox" class="hide">blank</div>
<h4>Surfing</h4>
</div></div></li>

So basically two questions:

  1. Why is not the mouse click simulated in some IE versions?

  2. Why is it not working in Firefox? (I had a problem with the event.preventdefault didn't work in firefox, but it's now fixed, see below)

See fully example on http://jgriph.se

Was it helpful?

Solution

Change

$(".trigger").live('click',function() {
 if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }

to

$(".trigger").live('click',function(event) {
 if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top