zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    VC++ 常用数学函数
    Skin++的使用 (成功在vs2008试过)
    解决switch使用String做参数 (jdk1.7新增),更改jdk版本后报错的问题
    [转]jdk1.7中 新增 switch 使用String 做参数 的实现
    [转]网页版Firebug
    [转]Eclipse导入工程后,XDoclet错误:Missing library: xdoclet1.2.1.jar. Select the home directory for XDoclet. 1.
    SAP related blogs
    [转]SAP FI/CO 模块设置
    如何调用BADI
    [转]一则关于ABAP程序员的趣谈
  • 原文地址:https://www.cnblogs.com/foreverfendou/p/7753706.html
Copyright © 2011-2022 走看看