1

こんにちは、画像があり、その画像をクリックすると、iframe として読み込まれた別の .aspx ページが呼び出されます。iframe 内のボタンをクリックすると、iframe が閉じます。さまざまな方法を試しましたが、どれも機能していません:

ここに私のiframeがあります:

function openBox() {
    $(".nodeOption, .nodeOptionBlack").fadeIn(200);
    var pageHeight = $(document).height();
    var pageWidth = $(document).width();
    $(".nodeOptionBlack").css("height", pageHeight).css("width", pageWidth);
}

$(document).ready(function() {
    $(".nodeOptionBlack").click(function () {
        $(".nodeOption, .nodeOptionBlack").fadeOut(200);
    });

    $(".WindowClose").click(function () {
        $(".nodeOption, .nodeOptionBlack").fadeOut(200);
    });

Here is my function of button click:

function Submit_Click() {
    var enroll = test();
    if (enroll == "sale") {
        a.Node(urlParams["parentid"], urlParams["placement"], 1, "Sale");
    }
    else {
        a.Node(urlParams["parentid"], urlParams["placement"], 1, "");
    }

//here i want to close my iframe 
}

i tried different things like:

  $("#nodeOption").remove();
  window.parent.closeIframe();

      //document.getElementById("nodeOption").parent.removeChild(iframe);
     //$('#nodeOption', top.document).dialog('close');
     // window.parent.closeIframe();
    //$(".nodeOption, .nodeOptionBlack").fadeOut(200);

function closeIframe() {
    alert("hi");
    var ifram = document.getElementById(".nodeOption");
    iframe.parent.removeChild(iframe);
}

私が間違っていることを提案してください.Thanks!

4

2 に答える 2

1

解決

jQueryを使っているので.remove()要素のメソッドを使います。ここでは、ID「iframe」の iframe を取得し、任意のbutton要素をクリックすると本文から削除します。

JavaScript/jQuery

/* This part is the put the button inside the iframe,
   it's not related to your problem */

$('#iframe').contents().find('body').append('<button>Click Here</button>');

/* We seek for a `button` element within the iframe body, in the iframe content */
$('#iframe').contents().find('body button').click(function (event) {
    event.preventDefault();
    $('#iframe').remove();
    $('#result').text('Iframe deleted!');
});

ああ、私を信じてください、あなたは純粋な JavaScript でこれを行いたくないでしょう (iframe の ownerDocument を取得して iframe 要素自体を削除しようとするまでは、すべてが簡単です)。

ライブデモ(更新)

于 2013-07-09T20:15:50.640 に答える
1

助けてくれてありがとう、私の問題は解決しました。ここで私がしたこと:

私のiframeでボタンをクリックすると、私は電話します

 window.parent.closeIframe1();

そして親ページで私はコーディングします:

  function closeIframe1()
        {
            $(".nodeOption, .nodeOptionBlack").fadeOut(200);
            return false;
        }

そしてそれは私にとってはうまくいきました。

于 2013-07-10T16:44:34.153 に答える