0
我需要從子頁面調用主頁面中的函數。下面我有2頁。 1. main.aspx和子頁面是2.active.aspx。在active.aspx中,我有一個名爲「exit」的按鈕,當我點擊退出按鈕時,我需要關閉模式彈出窗口,然後我需要調用主要頁面中的JavaScript函數「main」。我不能夠從子頁面調用該函數。從子頁面的父頁面調用JavaScript函數
Main.aspx
<html>
<head>
<script type="text/javascript">
function main() {
//do main work
}
</script>
</head>
<body>
<div>
<input type="button" class="ic-grid-encode center-btn" title="Interactive"
data-toggle="modal" data-target="#divInterActiveContent" />
</div>
<div class="modal fade" id="divInterActiveContent" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document" align-self="" center;"="">
<iframe id="interId" src="active.aspx"></iframe>
</div>
</div>
</body>
</html>
Active.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link href="../Content/bootstrap.css" rel="stylesheet">
<script src="../Scripts/jquery-3.1.1.js"></script>
<script src="../Scripts/bootstrap.js"></script>
<script src="../Scripts/knockout-3.4.2.js"></script>
<script src="../Scripts/jquery-ui-1.12.1.min.js"></script>
<script type="text/javascript">
self.btnExit = function() {
parent.$('#divInterActiveContent').modal('hide');
//after closing the popup i need to call the javascript function defined in the main page
//i.e i need call function main which is there in the main window.
}
</script>
</head>
<body>
<form id="frmInterActiveEncode">
<div class="container">
<div class="row" style="margin-top: 10px;">
</div>
<hr>
<br>
<hr>
<div class="row">
<input type="button" value="Submit" class="btn btn-primary" data-bind="event: { click: btnSubmit }">
<input type="button" value="Exit" class="btn btn-primary" data-bind="event: { click: btnExit }">
</div>
</div>
</form>
</body>
</html>
http://stackoverflow.com/questions/2379529/how-to-call-a-function-within-document-ready-from-outside-it –