js 执行跨域刷新页面
主要代码:
注意这段代码 是子页面中添加的也就是弹出的那个页面刷新父页面
<script type="text/javascript"> function shuaxin() { try { window.parent.opener.location.reload(); window.parent.close(); } catch (e) { window.parent.opener.location = "http://localhost:32859/test.aspx"; window.parent.opener = null; window.parent.close(); } } </script>
测试demo
首先新建一个web1,再新建一个test.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApp02.test" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript"> function OpenPage() { window.open('http://localhost:32858/testweb2.aspx', 'newwindow', 'height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no') } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="lblTest" runat="server" Text="还没开始测试"></asp:Label> <input id="Button1" type="button" value="button" onclick="OpenPage()" /> </div> </form> </body> </html>
test.aspx 后台代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApp02 { public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { lblTest.Text = "页面执行时间:" + DateTime.Now.ToLocalTime(); } Load(); } public void Load() { lblTest.Text = "页面执行时间:" + DateTime.Now.ToLocalTime(); } } }
再次新建一个web2,再新建一个testweb2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testweb1.aspx.cs" Inherits="WebApp01.testweb1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript"> function shuaxin() { try { window.parent.opener.location.reload(); window.parent.close(); } catch (e) { window.parent.opener.location = "http://localhost:32859/test.aspx"; window.parent.opener = null; window.parent.close(); } } </script> </head> <body> <form id="form1" runat="server"> <div> <input id="Text1" type="button" value="关闭当前页面" onclick="shuaxin()" /> </div> </form> </body> </html>
参考文章:http://www.xuebuyuan.com/838707.html
我的小鱼你醒了,
还认识早晨吗?
昨夜你曾经说,
愿夜幕永不开启。
初吻吻别的那个季节,
不是已经哭过了吗?
你的香腮边轻轻滑落的,
是你的泪,还是我的泪。
我的指尖还记忆著,
你慌乱的心跳。
温润的体香里,
那一缕长髮飘飘。
——青青树 《魁拔》
交流群:ASP.NET交流群(2群) 58189568
ExtJs4.2交流群(3群)97869295
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步