0
A
回答
0
我们可以在跨域环境中使用IFRAME。但我们必须使用阿贾克斯调用和IFRAME配置。以下是代码。它为我工作。我搜查了很多地区。 Atlast我得到了这个工作代码。
HTML
<iframe id="doc-frame" src="javascript:(function() {document.open();document.domain='localhost';document.close();})();" style="width:100%;height:100%;" seamless="seamless" scrolling="no" frameborder="0"></iframe>
在IFRAME我们必须设置域作为请求窗口文件的同一个域。否则它将无法工作。这里我设置了localhost。
JAVASCRIPT
$.support.cors = true;
var frameSize = 0;
$("#doc-frame").css({ 'height': frameSize, 'width': frameSize, 'zoom': '100%' });
$.ajax({
url: fileNamePath,// URL of the request page
context: document.body,
success: function (response) {
target = $("#doc-frame")[0].contentDocument;
target.open();
target.write(response);
target.close();
var frameMargin = 10;
$("#doc-frame").css("height", parseFloat($('#doc-frame').contents().height() + frameMargin) + "px");
$('#doc-frame').css("width", parseFloat($("#doc-frame").contents().width() + frameMargin) + "px");
}
});
它将工作。请使用此代码,并让我知道评论,缺点和限制。我不认为这可以满足我们所有的跨域IFRAME的需求。但在某些情况下,我们可以使用它。
谢谢
相关问题
- 1. 如何设置跨域的iframe高度
- 2. 跨域设置iframe高度动态
- 3. 根据文档的高度设置IFRAME的高度(跨域)
- 4. 跨域iframe高度操作
- 5. 如何设置colorbox iframe中图像的高度和宽度?
- 6. 在页面加载时设置iframe的高度和宽度
- 7. iframe的高度和宽度居中
- 8. 如何设置fancybox iframe的高度和宽度
- 9. 基于内容设置iFrame的宽度和高度
- 10. 设置链接的高度和宽度
- 11. tableGrob:设置grid.table的高度和宽度
- 12. 设置图像的宽度和高度
- 13. 设置场景的宽度和高度
- 14. 设置UIWebView的宽度和高度
- 15. 设置视频的宽度和高度
- 16. 设置高度和宽度的边距
- 17. 设置iframe高度
- 18. 跨域的动态iframe高度
- 19. 如何获得iframe跨域的高度
- 20. 调整跨域iframe的高度
- 21. 设置高度与宽度
- 22. iframe的宽度和高度值
- 23. 获取iframe的高度和宽度
- 24. iframe src全宽和高度
- 25. addchild设置宽度和高度
- 26. 将高度和宽度设置为img
- 27. 设置宽度和高度jsp页面
- 28. 设置rChart宽度和高度
- 29. UIPopoverPresentationController宽度和高度没有设置
- 30. UITextView在高度设置宽度和高度ForRowAtIndexPath
为什么重写jQuery的CORS支持检测?如果jQuery尝试在不支持它的浏览器中使用CORS会有什么好处呢? – Quentin 2014-10-16 10:37:07
一些请求只在我使用CORS时完成...... – 2014-10-16 10:50:08
覆盖jQuery的CORS支持检测不是“使用CORS”。 – Quentin 2014-10-16 10:51:18