2014-04-10 74 views
0

編輯(重述):在網站內加載的iframe,但我想用戶退出的iframe,當他們點擊這的iframe中1個鏈接,回到底層iframe的主窗口。打破I幀的出使用Javascript

我發現

top.location.href = 'page.htm'; 

,但我不知道怎麼把它進入到這個「複雜」的代碼。

這是我認爲它應該是這樣的文件:

{literal} 

$(document).ready(function() { 

    $('#payment_paypal_express_checkout').click(function() { 
     $('#paypal_payment_form').submit(); 
     return false; 
    }); 

    $('#paypal_payment_form').live('submit', function() { 
     var nb = $('#quantity_wanted').val(); 
     var id = $('#idCombination').val(); 

     $('#paypal_payment_form input[name=quantity]').val(nb); 
     $('#paypal_payment_form input[name=id_p_attr]').val(id); 
    }); 

    function displayExpressCheckoutShortcut() { 
     var id_product = $('input[name="id_product"]').val(); 
     var id_product_attribute = $('input[name="id_product_attribute"]').val(); 

     $.ajax({ 
      type: "GET", 
      url: baseDir+'/modules/paypal/express_checkout/ajax.php', 
      data: { get_qty: "1", id_product: id_product, id_product_attribute: id_product_attribute }, 
      cache: false, 
      success: function(result) { 
       if (result == '1') { 
        $('#container_express_checkout').slideDown(); 
       } else { 
        $('#container_express_checkout').slideUp(); 
       } 
       return true; 
      } 
     }); 
    } 

    $('select[name^="group_"]').change(function() { 
     displayExpressCheckoutShortcut(); 
    }); 

    $('.color_pick').click(function() { 
     displayExpressCheckoutShortcut(); 
    }); 

    {/literal} 
    {if isset($paypal_authorization)} 
    {literal} 

     /* 1.5 One page checkout*/ 
     var qty = $('.qty-field.cart_quantity_input').val(); 
     $('.qty-field.cart_quantity_input').after(qty); 
     $('.qty-field.cart_quantity_input, .cart_total_bar, .cart_quantity_delete, #cart_voucher *').remove(); 

     var br = $('.cart > a').prev(); 
     br.prev().remove(); 
     br.remove(); 
     $('.cart.ui-content > a').remove(); 

     var gift_fieldset = $('#gift_div').prev(); 
     var gift_title = gift_fieldset.prev(); 
     $('#gift_div, #gift_mobile_div').remove(); 
     gift_fieldset.remove(); 
     gift_title.remove(); 

    {/literal} 
    {/if} 
    {if isset($paypal_confirmation)} 
    {literal} 

     $('#container_express_checkout').hide(); 

     $('#cgv').live('click', function() { 
      if ($('#cgv:checked').length != 0) 
       $(location).attr('href', '{/literal}{$paypal_confirmation}{literal}'); 
     }); 

     // old jQuery compatibility 
     $('#cgv').click(function() { 
      if ($('#cgv:checked').length != 0) 
       $(location).attr('href', '{/literal}{$paypal_confirmation}{literal}'); 
     }); 

    {/literal} 
    {else if isset($paypal_order_opc)} 
    {literal} 

     $('#cgv').live('click', function() { 
      if ($('#cgv:checked').length != 0) 
       checkOrder(); 
     }); 

     // old jQuery compatibility 
     $('#cgv').click(function() { 
      if ($('#cgv:checked').length != 0) 
       checkOrder(); 
     }); 

    {/literal} 
    {/if} 
    {literal} 

    var modulePath = 'modules/paypal'; 
    var subFolder = '/integral_evolution'; 
    var fullPath = baseDir + modulePath + subFolder; 
    var confirmTimer = false; 

    if ($('form[target="hss_iframe"]').length == 0) { 
     if ($('select[name^="group_"]').length > 0) 
      displayExpressCheckoutShortcut(); 
     return false; 
    } else { 
     checkOrder(); 
    } 

    function checkOrder() { 
     confirmTimer = setInterval(getOrdersCount, 1000); 
    } 

    {/literal}{if isset($id_cart)}{literal} 
    function getOrdersCount() { 
     $.get(
      fullPath + '/confirm.php', 
      { id_cart: '{/literal}{$id_cart}{literal}' }, 
      function (data) { 
       if ((typeof(data) != 'undefined') && (data > 0)) { 
        clearInterval(confirmTimer); 
        window.location.replace(fullPath + '/submit.php?id_cart={/literal}{$id_cart}{literal}'); 
        $('p.payment_module, p.cart_navigation').hide(); 
       } 
      } 
     ); 
    } 
    {/literal}{/if}{literal} 
}); 

{/literal} 

編輯:發現了HTML的某些部分,以及,想通這將會是很容易做到那裏,但它不真正似乎上班。也許是因爲虛空(0)?

<a href="javascript:void(0)" target="_top" onclick="$('#paypal_payment_form').submit();" id="paypal_process_payment" mod='paypal'}"> 

也許有人在這裏可以幫助我。提前致謝!

最佳, 戴夫

回答

0

這是一些JavaScript如果網站被「的iframe」,將用戶重定向出來的iframe的網站:

<script>if (top !== self) top.location.href = self.location.href;</script> 
+0

謝謝!但是,我認爲我誤解了自己。 編輯我原來的帖子以及: 該網站被加載到一個iframe中,但是iframe中有1個鏈接,我希望用戶在他們點擊它時回到主窗口的底層iframe。 – CrossY

+0

你可以通過修改上面的JavaScript來完成,或者查看anchor標籤的target屬性:http://www.w3schools.com/tags/att_a_target.asp –

+0

謝謝Stephen!我試圖將它應用於HTML A標籤,但它沒有奏效。它在我刪除了VOID(0)並使其成爲「常規」鏈接時起作用。任何可能幫助我如何將它應用於上面的JavaScript? – CrossY

0

我不請參閱表格的一部分代碼,但由於您使用的是submit(),因此您可以將表單的目標設置爲_top:

<form target="_top" action="yoururl.php" id="paypal_payment_form"> 

然後,一旦您使用提交,它將打破框架並繼續到新的頁面。

<a href="#" onclick="$('#paypal_payment_form').submit();" id="paypal_process_payment" mod='paypal'>