2016-10-03 6 views
0

私は製品グリッドを持っており、各製品はiframeウィンドウを開くための一意のIDでjavascriptを呼び出します。 最初のものを呼び出すときは機能しますが、2番目のものを呼び出すときは何もしません。 私はそのスクリプトを呼び出す必要がある約20の製品を持っています。2つ以上の関数がJavascriptで実行できない

2番目のiframeを呼び出すときに可能であれば、最初に閉じる、2番目に表示するなどが必要です。ここで

はスクリプトです:

function init() { 

    test = true; 

    document.getElementById('go<?php echo $product['product_id']; ?>').onclick = function() { 
    ifr = document.createElement('iframe'); 
    ifr.setAttribute('src', this.href); 
    ifr.src = this.href; 
    ifr.setAttribute('id', 'iframe_a<?php echo $product['product_id']; ?>'); 

    if (test == true) { 
     ifr.onreadystatechange = function() { 
     if (this.readyState == 'complete<?php echo $product['product_id']; ?>') {} 
     } 
     document.getElementById('iframe_a_container<?php echo $product['product_id']; ?>').appendChild(ifr); 
     test = false; 
    } 
    return false; 
    } 
} 

window.addEventListener ? 
    window.addEventListener('load', init, false) : 
    window.attachEvent('onload', init); 

のiframeコード:

<div id="iframe_a_container<?php echo $product['product_id']; ?>"> </div> 

とボタンのコード:

<a id="go<?php echo $product['product_id']; ?>" href="index.php?route=product/quickview&amp;product_id=<?php echo $product['product_id']; ?>">Quick View</a> 

答えて

0

私はあなたが外(前IFRを宣言したことを前提としていonclick);ない場合は、あなたがそれを行う必要があります(だから、あなたがそれにアクセスするための基準を持っている)、この修正onclickのが動作するかどうか試してみてください。

document.getElementById('go<?php echo $product['product_id']; ?>').onclick = function() { 
    $(ifr).remove(); // Remove it from the screen 
    ifr = null; 
    ifr = document.createElement('iframe'); 
    ifr.setAttribute('src', this.href); 
    ifr.src = this.href; 
    ifr.setAttribute('id', 'iframe_a<?php echo $product['product_id']; ?>'); 

    if (test == true) { 
     ifr.onreadystatechange = function() { 
     if (this.readyState == 'complete<?php echo $product['product_id']; ?>') {} 
     } 
     document.getElementById('iframe_a_container<?php echo $product['product_id']; ?>').appendChild(ifr); 
     test = false; 
    } 
    return false; 
    } 
+0

あなたの方法では、ボタンがちょうどいない機能を持つhrefのような役割を果たします。 スクリプトが機能しなくなります。それはonclickの内側です。ここに作業スクリプトhttp://www.petite-style.com/tea(製品の下のクイックビューボタン)があります。 –

+0

はonmouseoverで試してみましたが、あなたのコードを少し変更して動作しますが、それは仕事をしません。 –

関連する問題