从iframe调用父文档javascript函数

从iframe调用父文档javascript函数

本文介绍了ajax成功后,从iframe调用父文档javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个aspx Web表单List.aspx&在ASP.net C#Web应用程序中的Link.aspx。

第一个用于列出所有博客文章。



第二个是用于链接文章索引中的所有未链接文章。这篇文章索引是我维护文章层次结构的地方,它通过树视图控件显示在另一个页面上。



这些文章通过使用ASP.net中的DataList控件。这些文章存储在SQL Server 2012数据库表中。



I have two aspx Web form List.aspx & Link.aspx in a ASP.net C# Web App.
The first one is for listing all blog articles.

The second one is for linking all unlinked articles in the article index. This article index is a place where I maintain article hierarchy which gets displayed via a treeview control on a different page.

These article are getting listed on the form by using an DataList control in ASP.net. These articles are stored in SQL Server 2012 database table.

<div class="list_result_small shadow" data-aid="1">
  <div class="list_logo">
    <a title="Click to view details" href="../ViewDetails.aspx?aid=1" target="_blank"><img class="logo" alt="" src="../css/images/logo-192x192.png"></a>
  </div>
  <div class="list_detail_small">
    <span class="list_field">Article Title : Test</span><br>
    <span class="list_field">Article Author : </span><span class="black-text">Author Names as CSV</span><br>
    <span class="list_field">Article Category : </span><span class="black-text">Category Names as CSV</span><br>
    <span class="list_field">Article Tag : </span><span class="black-text">Tag Names as CSV</span><br>
    <span class="list_field">Created Date : 21 Nov 2015 13:07:22</span><br>
    <span class="list_field">Updated Date : 21 Nov 2015 13:08:11</span><br>
    <span class="list_field">Article Status : </span><span class="astatus span-yes">Published</span><br>
    <span class="list_field">Version : 1</span><br>
    <span class="list_field">Is Article Linked to Index : </span><span class="alinked span-no">No</span><br>
    <span class="list_field">Is Subscribable : </span><span class="suballow span-yes">Yes</span><br>
    <span class="list_field">Is Active : Yes</span><br>
    <span class="list_field">Is Subscribed : </span><span class="allow span-yes">Yes</span><br>
    <span class="list_field">Description : Test</span>
  </div>
  <div class="list-buttons">
    <div class="list-action shadow pub-button unpublish">
      <a id="id-1" href="java<!-- no -->script:void(0);" class="list-action-all pub-link unpublish-link">Unpublish</a>
    </div>
    <div class="list-action shadow subscribe-button unsubscribe">
      <a id="aid-1" href="java<!-- no -->script:void(0);" class="list-action-all unsubscribe-link">Unsubscribe</a>
    </div>
    <div class="list-action shadow">
      <a href="../CMS/Read.aspx?aid=1" class="fancybox list-action-all" data-fancybox-type="iframe">Read</a>
    </div>
    <div class="list-action shadow">
      <a href="../CMS/ViewDetails.aspx?aid=1" target="_blank" class="list-action-all">View</a>
    </div>
    <div class="list-action shadow">
      <a href="../CMS/Update.aspx?aid=1" target="_blank" class="list-action-all">Update</a>
    </div>
    <div class="list-action shadow unlink-button link">
      <a id="lid-1" href="../CMS/Link.aspx?aid=1" class="list-action-all unlink-link alink fancybox-link" data-fancybox-type="iframe">Link</a>
    </div>
  </div>
</div>





当我点击fancybox-link锚标签时,fancybox iframe叠加打开第二个网络表单链接。其中的aspx。在Link.aspx Web表单中,用户执行ajax请求以将文章链接到适当的文章索引。



我想要实现的是在链接中的ajax成功。 aspx web表单我想调用head部分List.aspx页面中声明的javascript函数。



我完全向你保证没有交叉原点错误两个页面都在同一个域。



我尝试的代码如下。



When I click on the fancybox-link anchor tag an fancybox iframe overlay opens up the second web form Link.aspx within it. In the Link.aspx web form users perform an ajax request to link article to appropriate article index.

What i want to achieve is that on ajax success in the Link.aspx web form I want to call the javascript function declared in the List.aspx page in the head section.

I completely assure you that there is no cross origin error as both pages are on the same domain.

The code that i tried is as follows.

$.ajax({......
.......the usual parameters
success: function(response){
    if(response.d == 'success'){
       parent.ParentFunction(boolVal,stringval);
    }
},
error:function(){
alert('Error occured while linking article');
}





这个方法不起作用,因为它抛出一个错误,上面写着'Uncaught TypeError parent.ParentFunction不是一个函数'



注意:ParentFunction()在List.aspx页面的$(document).ready()函数中声明。



请告知如何从iframe中调用js函数。



提前致谢。



This method is not working as it throws an error which says 'Uncaught TypeError parent.ParentFunction is not a function'

Note : The ParentFunction() is declared within the $(document).ready() function on the List.aspx page.

Kindly advise on how to call js function from within the iframe.

Thanks in advance.

推荐答案





此方法不起作用,因为它抛出一个错误,上面写着'Uncaught TypeError parent.ParentFunction不是函数'



注意:ParentFunction()在List.aspx页面的



This method is not working as it throws an error which says 'Uncaught TypeError parent.ParentFunction is not a function'

Note : The ParentFunction() is declared within the



Christopher Fernandes写道:
Christopher Fernandes wrote:



ParentFunction()在


The ParentFunction() is declared within the

中声明

这篇关于ajax成功后,从iframe调用父文档javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:56