我在本地机器上访问服务器上的页面(A.html),页面A上有用window.open()打开我本地机器上的页面(B.html),
我想在服务器页面A的javascript中调用本地机器页面B的一个javascript方法setValues()。
于是,我在页面a上,把window.open()子窗口对象保存到subwindow变量中,然后用subwindow.setValues();这样调用,
但是出现权限问题,拒绝访问。
在网上查过很多,可能是理解问题,没总结出一个方法,请问有什么解决方法能实跨域调用方法呢?谢谢!
我想在服务器页面A的javascript中调用本地机器页面B的一个javascript方法setValues()。
于是,我在页面a上,把window.open()子窗口对象保存到subwindow变量中,然后用subwindow.setValues();这样调用,
但是出现权限问题,拒绝访问。
在网上查过很多,可能是理解问题,没总结出一个方法,请问有什么解决方法能实跨域调用方法呢?谢谢!
解决方案 »
- 含有html标签的信息分页 应该如何解决??
- 鼠标放在图片上显示大图
- 这个javascript为什么不能得到杀毒软件是否更新呢? 急
- 不管点确定还是取消,都执行了submit
- textarea的格式
- 非表单提交数据修改,不成功,请帮忙修改代码!
- 关于div定位的问题。求教如何利用js改写div的left值!
- DHTML的对象为什么会变?
- 请问用document.write("<table ...生成的表格,如何清除或使其不可见?
- GitHub上下的源码,不知道这怎样布置到服务器上 求大佬们指点一下 谢谢
- jquery如何删除重复DIV,等高手
- 关于window.open()使用之后的问题,请教高手
然后你本机的代码你自己是可以改的。服务器端接收到参数后直接显示在页面上就行。
http://blog.csdn.net/charrys/archive/2010/09/17/5890451.aspx
希望对你有帮助!
然后在a页面中调用parent.functionName();
一般子页面可以调用父页面。但是如果是父页页调用子页面(如果跨域的话就要设置比较麻烦)。
www.abc.com -->a页面
本机器的(http://www.localhost/)--->B页面
我不知道这种测试能不能成功。但感觉没有必要做这样的需求啊!
即你给frame加一个比如叫a的属性
然后A页面给b页面这个frame的a传值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
<input type="button" id='btn' value="load" />
<input type="button" id='btn2' value="run" />
<script type="text/javascript">
$(document).ready(function () {
window.flag = '';
$('#btn').click(function() {
$('body').append('<iframe src="http://b.com/B.html"></iframe>');
});
$('#btn2').click(function() {
window.flag = '弹出就成功!';
});
});
</script>
</body>
</html>//AA.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
setTimeout(function() {
var s = window.parent.parent.flag;
if(s != '') {
$('body').append('<iframe src="http://b.com/BB.html#' + s + '"></iframe>');
} else {
setTimeout(arguments.callee, 100);
}
}, 100);
});
</script>
</body>
</html>b.com下有两个页面B,html, BB.html//B.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
window.msg = function(str) {
alert(str);
}
$('body').append('<iframe src="http://a.com/AA.html"></iframe>');
});
</script>
</body>
</html>//BB.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
var s = location.hash.substr(1);
window.parent.parent.msg(s);
</script>
</body>
</html>
我对你的代码理解是这样:BB.html通过调用B.html的方法msg(),来显示出A.html里面的flag值。
这个跨域传值是做到了,可是我需要的是跨域调用方法,
比如:在BB.html中调用AA.html或A.html中的方法,我用你的方法试了,不过不成功。
还有不用iframe,我是用window.open打开另一个域里的子页面,子页面和父页面不在一个域。
需求:子页面能调用父页面的方法。
如果理解不对,请指正。如果确实没方法能实现,我只能重新想方法做。
你用DIV模拟弹窗不是一样的。