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解决跨域问题
今天看了看以前做的一个小项目(其实就是一个页面),分享一下当时解决跨域问题的: 背景:公司把项目部署在多台服务器上,防止一台服务器崩溃后,其他的可以继续访问,对应本公司来说,某台服务器出问题后,技术人 ...
随机推荐
- db2 相关命令
db2ilist ---列出主机所有实例 db2icrt instanceName ---创建实例名为instanceName的实例 db2idrop instanceName ---删 ...
- mysql 中调用存储过程之后,连接断开不可用
解决方法: 由 mysql_real_connect(&m_mysql,host,user,passwd,Db,0,NULL,0) == NULL 改为 mysql_real_connect( ...
- dot 使用笔记
Graphviz (英文:Graph Visualization Software的缩写)是一个由AT&T实验室启动的开源工具包,用于绘制DOT语言脚本描述的图形 sudo apt-get i ...
- 开机启动/etc/rc.local失效无效怎么办?解决方法
开机启动/etc/rc.local失效问题的解决方法 第一种情况:当centOS 随机启动文件 /etc/rc.local 失效时请按如下修改1.echo /etc/rc.local >> ...
- MySQL 乐观锁与悲观锁
悲观锁 悲观锁(Pessimistic Lock),顾名思义,就是很悲观,每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这个数据就会block直到它拿到锁. 悲观锁: ...
- travelsal all files in a dir using recursion shell
#!/bin/bash function getdir(){ ` do dir_or_file=$"/"$element if [ -d $dir_or_file ] then g ...
- 静默安装oracle 11g及参数配置优化详解
一.安装前准备工作1.修改主机名#vi /etc/hosts //并添加内网IP地址对应的hostname,如下127.0.0.1 localhost::1 ...
- android studio中取消关联git
Android studio取消关联Git 步骤如下 settings->version control 这里是已经取消关联的 如果关联 按住减号即可
- 对 tensorflow 中 tf.nn.embedding_lookup 函数的解释
http://stackoverflow.com/questions/34870614/what-does-tf-nn-embedding-lookup-function-do embedding_l ...
- Python基础-面向对象2
一.成员修饰符 共有成员 私有成员:创建方式在成员之前加两个下划线,私有成员无法直接访问,只能间接访问 子类不能继承父类的私有属相私有普通字段的访问方式: class Fansik: def __in ...