87,907
社区成员
发帖
与我相关
我的任务
分享
function sendPost(){
var postStr, ifrm;
postStr = document.getElementById('ps_cmt').innerHTML;
ifrm = document.createElement("iframe");
ifrm.setAttribute("id",'commentFrm');
ifrm.src='about:blank';
ifrm.setAttribute("frameborder","0");
ifrm.setAttribute("name",'commentFrm');
ifrm.contentDocument.write('<form method="POST" action="http://my.domain.com/request.php"><textarea name="txtData">'+postStr+'</textarea></form>');
ifrm.contentDocument.forms[0].submit();
}
function sendPost(){
var postStr, ifrm;
postStr = document.getElementById('ps_cmt').innerHTML;
ifrm = document.createElement("iframe");
ifrm.setAttribute("id",'commentFrm');
ifrm.src='about:blank';
ifrm.setAttribute("frameborder","0");
ifrm.setAttribute("name",'commentFrm');
ifrm.contentDocument.write('<form method="POST" action="http://my.domain.com/request.php"><textarea name="txtData">'+postStr+'</textarea></form>');
ifrm.contentDocument.forms[0].submit();
}
写了一个,报错了TypeError: ifrm.contentDocument is null,估计iframe也有跨域说明。[/quote]
。。。忘了说了。。。contentDocument是webkit特有的iframe获取document接口,ie直接用document就可以了。这个报错明显不是跨域问题。。。[/quote]
$(window.frames["iframe1"].document).find("#testid").val(obj.areaData);
alert($(window.frames["iframe1"].document).find("#testid").val());
$(window.frames["iframe1"].document).find("#form2").submit();
我是这么使用的,submit不好使。alert是可以获得数据的。function sendPost(){
var postStr, ifrm;
postStr = document.getElementById('ps_cmt').innerHTML;
ifrm = document.createElement("iframe");
ifrm.setAttribute("id",'commentFrm');
ifrm.src='about:blank';
ifrm.setAttribute("frameborder","0");
ifrm.setAttribute("name",'commentFrm');
ifrm.contentDocument.write('<form method="POST" action="http://my.domain.com/request.php"><textarea name="txtData">'+postStr+'</textarea></form>');
ifrm.contentDocument.forms[0].submit();
}
function sendPost(){
var postStr, ifrm;
postStr = document.getElementById('ps_cmt').innerHTML;
ifrm = document.createElement("iframe");
ifrm.setAttribute("id",'commentFrm');
ifrm.src='about:blank';
ifrm.setAttribute("frameborder","0");
ifrm.setAttribute("name",'commentFrm');
ifrm.contentDocument.write('<form method="POST" action="http://my.domain.com/request.php"><textarea name="txtData">'+postStr+'</textarea></form>');
ifrm.contentDocument.forms[0].submit();
}
写了一个,报错了TypeError: ifrm.contentDocument is null,估计iframe也有跨域说明。[/quote]
。。。忘了说了。。。contentDocument是webkit特有的iframe获取document接口,ie直接用document就可以了。这个报错明显不是跨域问题。。。
<div id="ps_comment"></div>
<script type="text/javascript">
var comment_conf = {app_id:"1212"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = 'http://www.ping.com/api/comment.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
而评论的数据都是www.ping.com域名上的, 所以www.a.com页面中的js需要向www.ping.com提交数据。使用代理是在www.a.com实现的。这样就不符合要求了。[/quote]
加载数据基本没有域名限制,主要是提交数据时别人的站点。。
不用后续的控制可以采用iframe,如果有后续的操作,如根据返回值进行某些操作iframe跨域不行
可以用ajax,动态页设置Access-Control-Allow-Origin响应头为“*”,任何域名发送的ajax都可以请求这个动态页。不过IE7-浏览器无法请求,即使设置了这个响应头,ie8+要使用XDomainRequest这个对象,而不是acx或者XMLHttpRequest。
参考:access-Control-Allow-Origin跨域请求安全隐患
所以兼容性好只能a.com做代理请求你的ping.comfunction sendPost(){
var postStr, ifrm;
postStr = document.getElementById('ps_cmt').innerHTML;
ifrm = document.createElement("iframe");
ifrm.setAttribute("id",'commentFrm');
ifrm.src='about:blank';
ifrm.setAttribute("frameborder","0");
ifrm.setAttribute("name",'commentFrm');
ifrm.contentDocument.write('<form method="POST" action="http://my.domain.com/request.php"><textarea name="txtData">'+postStr+'</textarea></form>');
ifrm.contentDocument.forms[0].submit();
}
function sendPost(){
var postStr, ifrm;
postStr = document.getElementById('ps_cmt').innerHTML;
ifrm = document.createElement("iframe");
ifrm.setAttribute("id",'commentFrm');
ifrm.src='about:blank';
ifrm.setAttribute("frameborder","0");
ifrm.setAttribute("name",'commentFrm');
ifrm.contentDocument.write('<form method="POST" action="http://my.domain.com/request.php"><textarea name="txtData">'+postStr+'</textarea></form>');
ifrm.contentDocument.forms[0].submit();
}
写了一个,报错了TypeError: ifrm.contentDocument is null,估计iframe也有跨域说明。
<div id="ps_comment"></div>
<script type="text/javascript">
var comment_conf = {app_id:"1212"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = 'http://www.ping.com/api/comment.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
而评论的数据都是www.ping.com域名上的, 所以www.a.com页面中的js需要向www.ping.com提交数据。使用代理是在www.a.com实现的。这样就不符合要求了。