有2个页面A和B,
A页面使用iframe包含B页面
测试如下:
A页面代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script src="../js/jquery.uploadify/jquery.uploadify.js" type="text/javascript"></script>
<link href="../js/jquery.uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function test() { window.frames["content"].autoRefresh1();
return false;
} function test1() { clearInterval(window.frames["content"].autotimer);
return false;
} </script>
</head>
<body>
<form id="form2" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="test();return false;" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClientClick="test1();return false;" />
<iframe id='content' name="content" src="WebForm1.aspx" width="100%" height="100%">
</iframe>
</form>
</body>
</html>
B页面如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
var autotimer = null;
function autoRefresh1() {
autotimer = setInterval("myfunction()", 1000);
}
function myfunction() {
$('#<%=Button1.ClientID %>').click();
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
点击A页面Button1,启动B页面的setInterval方法,
启动后,点击A页面的Button2,通过js来停止B页面的autotimer ,但是不起作用啊js autotimer setInterval
A页面使用iframe包含B页面
测试如下:
A页面代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script src="../js/jquery.uploadify/jquery.uploadify.js" type="text/javascript"></script>
<link href="../js/jquery.uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function test() { window.frames["content"].autoRefresh1();
return false;
} function test1() { clearInterval(window.frames["content"].autotimer);
return false;
} </script>
</head>
<body>
<form id="form2" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="test();return false;" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClientClick="test1();return false;" />
<iframe id='content' name="content" src="WebForm1.aspx" width="100%" height="100%">
</iframe>
</form>
</body>
</html>
B页面如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
var autotimer = null;
function autoRefresh1() {
autotimer = setInterval("myfunction()", 1000);
}
function myfunction() {
$('#<%=Button1.ClientID %>').click();
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
点击A页面Button1,启动B页面的setInterval方法,
启动后,点击A页面的Button2,通过js来停止B页面的autotimer ,但是不起作用啊js autotimer setInterval
function test1() {
var win=window.frames["content"];
win.clearInterval(win.autotimer);
return false;
}试试