1

Web サイトで、起動時に全画面表示される写真スワイプ アプリケーションを含む iframe を作成しました。これで、写真スワイプ スライドショーを iframe の外部から制御する必要があります。メインサイトにこのコードがあります:

<iframe src="test.html" id="iframe" width="1440" height="1080" name="iframe" scrolling="no" frameBorder="0" ></iframe>
<div id="ruck" ><a href="#" onClick="document.getElementById('iframe').contentWindow.previous();"><img src="img/rueck.png" /></a></div>
<div id="vor" ><a href="#" onClick="document.getElementById('iframe').contentWindow.next();"><img src="img/vor.png" /></a></div>

そしてiframeのこのコード:

<html>
<head>
    <link href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.css" rel="stylesheet" />
    <link href="photoswipe.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="klass.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>
    <script type="text/javascript" src="code.photoswipe.jquery-3.0.4.min.js"></script>
    <script type="text/javascript">
        (function(window, $, PhotoSwipe)
        {
            $(document).ready(function()
            {
                 var myPhotoSwipe = $("#gallery a").photoSwipe(
                {
                    enableMouseWheel: false,
                    enableKeyboard: false,
                    captionAndToolbarHide: false
                });

                $("#gallery a:first").click();
            });
        }
        (window, window.jQuery, window.Code.PhotoSwipe));

function previous()
{
myPhotoSwipe.previous(); 
}

function next()
{
myPhotoSwipe.next(); 
}       
</script>
</head>
<body>
<div id="gallery">      
            <a href="demo/image001.jpg" rel="external"></a>
            <a href="demo/image002.jpg" rel="external"></a>
            <a href="demo/image003.jpg" rel="external"></a> 
        </div>
</body>
</html>

ここでは、次の前のボタンをクリックするとエラーが発生しました。 ReferenceError: myPhotoSwipe is not defined myPhotoSwipe.next();

ご覧のとおり、イベントは発生していますが、関数 myPhotoSwipe.next() は未定義です。実行中のコードで何を変更すればよいですか?

前もって感謝します。

4

1 に答える 1