views:

717

answers:

1

Hi,

I know this issue has been discussed before but I can't seem to get it to work. I have a master html page with an iframe on that page. I am using jquery prettyphoto and I was wondering how I can get the light box to display in the parent window when I click on the link in the iframe?

Please my code below:

Master Page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Master Page</title>
</head>

<body>
 <iframe src="iframe.html" width="300" height="300px" frameborder="0"></iframe>
</body>
</html>

iFrame Page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>iframe</title>

<style type="text/css" media="screen">
 @import url("assets/css/infotech-iframes.css");
 @import url("assets/css/infotech-popup.css");
</style>

<script src="assets/js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/js/jquery.popup.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
 <a href="assets/images/screenshots/campaign-setup-lg.png" rel="prettyPhoto[gallery]"><img src="assets/images/screenshots/campaign-setup-sm.gif" /></a>
<script type="text/javascript" charset="utf-8">

$(document).ready(function(){ $("a[rel^='prettyPhoto']").prettyPhoto(); });


Thanks for any help provided.

A: 

This will only work if the domain for the parent and child frames are the same.

You'll need to load the necessary JavaScript in the parent frame. Then try something like this in the iframe:

$(document).ready(function(){
    $('a').click(function(){
        window.parent.$.prettyPhoto.open($(this).attr('src'), $(this).attr('title'), $(this).children('img').attr('alt'));
        return false;
    });
});

You might have to change the $('a') selector to something else. I don't think you should put rel on the links because you might get pretty photo opening in both the parent and the iframe.

This should all work in theory. I have not tested it.

CalebD
Hi,I tried your suggestion but still get the same result of the lightbox displaying within the iframe instead of the parent page. Would you have anu further suggestions.Thanks
Kurt
Were there any JavaScript errors? Did you remove the rel attribute from the <a> tags? Does pretty photo work from the parent frame if you call it manually as a test? Are you using the most recent version of pretty photo?
CalebD