我得到了一個在JScript.js文件中定義的js函數。該文件在主頁面上定義。我想從inIframe.aspx頁面調用這個文件中的sayhello函數。這個inIframe.aspx在webform1.aspx頁面內運行,webform1.aspx頁面有一個名爲masterWithJs.master的主頁面。錯誤:window.parent.sayhello不是一個函數?
時,我打:
http://localhost:8022/inIframe.aspx
我的螢火得到一個腳本錯誤:
window.parent.sayhello is not a function
母版:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="masterWithJs.master.cs"
Inherits="IFrameJS.masterWithJs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
<script src="Scripts/JScript1.js" type="text/javascript"></script>
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
WebForm1.aspx的
<%@ Page Title="" Language="C#" MasterPageFile="~/masterWithJs.Master" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="IFrameJS.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<iframe id="myIframe" runat="server"></iframe>
</asp:Content>
inIframe.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="inIframe.aspx.cs" Inherits="IFrameJS.inIframe" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
this is the iframe page
</div>
</form>
<script type="text/javascript">
window.parent.sayhello();
</script>
</body>
</html>
JScript1.js
function sayhello() {
alert('hello');
}
WebForm1.aspx的behindcode:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
myIframe.Attributes.Add("src","inIframe.aspx");
}
}
謝謝大家!該腳本文件沒有根據螢火蟲加載,現在它! – user603007