簡體   English   中英

搜索Iframe跨域

[英]Searching for Iframe Cross domain

我試圖更改其中包含另一個網站的域URL的iframe(從MVC視圖打開)的URL。 當我嘗試檢索iframe對象時,無法獲取它。 這是我嘗試過的不同方法。 最終,我只想在iframe關閉時更改其網址。

更新:當我嘗試使用傳遞的URL獲取iframe時,在iframe調試器中收到“權限被拒絕”錯誤。

$(document).on('click', '.ui-dialog-titlebar-close', function () {
    var id = 'frame1';
    var iframe = document.frames ? document.frames[id] : document.getElementById(id);
    var x = document.getElementById(id);
    var z =  $(id);

    //doAlert();
});

 @using (Html.BeginActionLinkDialog(new DialogOptions()
                                            {
                                                OpenURL = @Model.TitleManagerURL,
                                                OpenDialogWithIFrame = true,
                                                Title = "Title Manager",
                                                Resizable = true,
                                                Height = "500",
                                                Width = "1200",   

                                                TargetDialogId = "xx"
                                            }, new { @id = "id1", @class = "edition_sub_link" }))

使用以下代碼更改點擊事件中的iFrame URL。

您的iFrame:

<iframe id="iframeLanding" width="100%" scrolling="no" height="500px"  > </iframe>

此處的菜單僅用於具有不同域URL的(例如,可以是任何內容):

<Div>
 <a href="https://www.google.com" class='menu' />
 <a href="https://www.stackoverflow.com" class='menu' />
</Div>

用於更新iFrame URL並調整其大小的代碼。

 $(document).on('click', '.menu', function(event) {
   event.preventDefault();
   var url = $(this).attr("href");
   $('#iframeLanding').attr('src', url);
   setTimeout("iframeLoad()", 3000);
});

function iframeLoad(){
  resizeIFrame();
  $("#iframeLanding").load(reSizeIFrame);
}

function resizeIFrame() {
  try {
     var helpFrame = jQuery("#iframeLanding");
     var innerDoc = (helpFrame.get(0).contentDocument) ? helpFrame.get(0).contentDocument : helpFrame.get(0).contentWindow.document;
                     helpFrame.height(innerDoc.body.scrollHeight + 35);
      } catch (e) { var g = 1; }
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM