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 执行跨域刷新页面的更多相关文章
- js执行跨域请求
//js执行跨域请求 var _script = document.createElement('script'); _script.type = "text/javascript" ...
- js&jquery跨域详解jsonp,jquery并发大量请求丢失回调bug
URL 说明 是否允许通信 http://www.a.com/a.js http://www.a.com/b.js 同一域名下 允许 http://www.a.com/lab/a.js http:/ ...
- JS JSOP跨域请求实例详解
JSONP(JSON with Padding)是JSON的一种“使用模式”,可用于解决主流浏览器的跨域数据访问的问题.这篇文章主要介绍了JS JSOP跨域请求实例详解的相关资料,需要的朋友可以参考下 ...
- JS Ajax跨域访问
js ajax跨域访问报"No 'Access-Control-Allow-Origin' header is present on the requested resource 如果请求的 ...
- js调用跨域
web aapi 初体验 解决js调用跨域问题 跨域界定 常见跨域: 同IP不同端口: http:IP:8001/api/user http:IP:8002/api/user 不同IP不同 ...
- react-native debug js remotely跨域问题
react-native debug js remotely跨域问题 我们在安卓真机上调试react-native时,启用debug js remotely的时候,会出现跨域问题.这个时候我们只需要一 ...
- 静态页面调试JS出现跨域问题
在chrome浏览器或者firefox浏览器里,由于安全限制的原因,本地调试JS,如果不配服务器环境而直接打开页面,那所有的AJAX操作会抛出下面错误: XMLHttpRequest cannot l ...
- 搞懂:前端跨域问题JS解决跨域问题VUE代理解决跨域问题原理
什么是跨域 跨域:一个域下的文档或脚本试图去请求另一个域下的资源 广义的跨域包含一下内容: 1.资源跳转(链接跳转,重定向跳转,表单提交) 2.资源请求(内部的引用,脚本script,图片img,fr ...
- 后台访问 JS解决跨域问题
今天看了看以前做的一个小项目(其实就是一个页面),分享一下当时解决跨域问题的: 背景:公司把项目部署在多台服务器上,防止一台服务器崩溃后,其他的可以继续访问,对应本公司来说,某台服务器出问题后,技术人 ...
随机推荐
- 爬虫实战【10】利用Selenium自动登陆京东签到领金币
今天我们来讲一下如何通过python来实现自动登陆京东,以及签到领取金币. 如何自动登陆京东? 我们先来看一下京东的登陆页面,如下图所示: [插入图片,登陆页面] 登陆框就是右面这一个框框了,但是目前 ...
- border-radius 原理分析
border-radius 想必大家都有所了解,比较常见的用法就像下面一样: 注意左边的盒子 border-radius: 100px; 右边的为0哦,所以右边的实际上没有设置圆角边框属性:咱们比较 ...
- 局域网查看工具Lansee注册码
相信好多人为查看局域网IP发愁,今天给大家推荐一个工具 lansee 猛戳下载
- Apache-ActiveMQ transport XmlMessage
前言 本文原创,转载请说明出处! Apache-ActiveMQ:是Apache提供的一款开源的消息传送服务,不论是安装还是使用都非常简单实用,可以作为消息缓存管理器来使用(个人观点),看看Activ ...
- C#自动给文章关键字加链接实现代码
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...
- HTTP协议及其POST与GET操作差异 & C#中如何使用POST、GET等
转自: http://www.cnblogs.com/skynet/archive/2010/05/18/1738301.html 引言 HTTP协议我想任何IT人士都耳熟能详了,大家都能说出个所以然 ...
- datagridview数据导出到excel
/// <summary> /// 导出Excel /// </summary> /// <param name="mydgv">控件 Data ...
- 002-主流区块链技术特点及Hyperledger Fabric V0.6版本特点
一.主流区块链技术特点 二.HyperLedger子项目 三.Hyperledger fabric架构 V0.6逻辑架构: V0.6区块链网络 对应的0.6版本的运行时架构: 0.6版本的架构特点是: ...
- 编译原理课后习题答案令A,B和C是任意正规式,证明以下关系成立(A|B)*=(A*B*)*=(A*|B*)*
题目: 令A.B和C是任意正规式,证明以下关系成立: A∣A=A (A*)*= A* A*=ε∣A A* (AB)*A=A(BA)* (A∣B)*=(A*B ...
- 吴超老师课程--Hbase Shell
hbase提供了一个shell的终端给用户交互 名称 命令表达式 创建表 create '表名称', '列族名称1','列族名称2','列族名称N' 添加记录 put '表名称', '行名称', '列 ...