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解决跨域问题
今天看了看以前做的一个小项目(其实就是一个页面),分享一下当时解决跨域问题的: 背景:公司把项目部署在多台服务器上,防止一台服务器崩溃后,其他的可以继续访问,对应本公司来说,某台服务器出问题后,技术人 ...
随机推荐
- Manacher模板,kmp,扩展kmp,最小表示法模板
*N]; //储存临时串 *N];//中间记录 int Manacher(char tmp[]) { int len=strlen(tmp); ; ;i<len;i++) { s[cnt++]= ...
- Jenkins publish over ssh 路劲配置问题 记录
每次通过jenkins 实现 maven项目编辑后 自动通过 ssh发布到 服务器的功能时,对配置的路劲有疑问,特整理出来 前提:服务器路径 /home/ubuntu/aps 目标: 构建后的j ...
- 【BZOJ4543】[POI2014]Hotel加强版 长链剖分+DP
[BZOJ4543][POI2014]Hotel加强版 Description 同OJ3522数据范围:n<=100000 Sample Input 7 1 2 5 7 2 5 2 3 5 6 ...
- java.lang.IllegalArgumentException: Failed to decrypt.
加密失败. 附加信息: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Co ...
- JavaScript学习笔记-Js操控HTML5 <progress> 标签
Js操控----HTML5 <progress> 标签 简单模拟下下载进度跑条 <h4>加载进度</h4> <input type="button& ...
- 【转】Startssl SSL 证书申请图解
一.什么是 SSL 证书,什么是 HTTPS 网站? SSL证书是数字证书的一种,类似于驾驶证.护照和营业执照的电子副本.SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(Secu ...
- caffe使用(1)
caffe使用 caffe是一个卓越的CNN框架 caffe源码是Cpp语言的,基于一些外部的库,包括BLAS(矩阵计算),CUDA(GPU驱动),gflags,glog,boost,protobuf ...
- Log4j:log4j.properties 配置解析
Log4j 三个主要组件 Loggers(记录器):记录日志的工具,程序中就是用它来记录我们想要的日志信息. Appenders (输出源):日志输出到什么地方,可以是控制台.文件.流位置.数据库,等 ...
- 我的Android进阶之旅------>Android Studio 快捷键整理分享
正式转战Android Studio了,首先把Android Studio的快捷键摘录下来,以备后用. (官网的快捷键列表如下 https://developer.android.com/studi ...
- 系列文章(三):WAPI为无线局域网WLAN安全而生——By Me
导读:无线局域网(又称为WLAN,Wireless Local Area Network),其应用领域不断拓展,无线接入所具有的前所未有的连接性和自动化能够为人们带来巨大的便利和商机.与此同时,在信息 ...