简体   繁体   English

使用JavaScript突破iframe

[英]Breaking out of iframes with Javascript

Edit (rephrasing): the website is loaded within an iframe, but there is 1 link inside the iframe which I would like to take the user out of the iframe when they click it , back into the main window that underlays the iframe. 编辑(改写):该网站已加载 iframe中,但是iframe中有1个链接,当用户单击iframe时我希望该用户退出iframe ,并返回到构成iframe的主窗口。

I've found 我发现了

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

, but I wouldn't know how to enter it into this 'complex' code. ,但我不知道如何将其输入此“复杂”代码中。

This is the file I believe it should be in: 我认为该文件应该位于:

{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}

Edit: found some part of the HTML as well, figured it'd be easy to do there, but it doesnt actually seem to work. 编辑:也找到了HTML的某些部分,认为这样做很容易,但实际上似乎没有用。 Perhaps because of the void(0)? 也许是因为void(0)?

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

Perhaps someone here can help me out. 也许有人可以帮助我。 Thanks in advance! 提前致谢!

Best, Dave 最好的,戴夫

这是一些JavaScript,如果网站处于“ iframe”状态,则会将用户从iframe重定向到该网站:

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

I do not see a portion of the code for your form, but since you are using submit() you can set the target of the form to _top: 我看不到表单代码的一部分,但是由于您使用的是Submit(),因此可以将表单的目标设置为_top:

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

Then once you use submit, it will break the frames and continue to the new page. 然后,一旦您使用提交,它将打破框架并继续到新页面。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM