分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

js 执行跨域刷新页面

发布时间:2023-09-06 01:21责任编辑:顾先生关键词: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

js 执行跨域刷新页面

原文地址:http://www.cnblogs.com/foreverfendou/p/7753706.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved