iframe cross domain communication

shenhongsh 2009-04-29 03:14:06
Background:
1. There are two jsp InvokeEService.jsp and trafficViolationMain.jsp. InvokeEService.jsp is in domain “stg.www.gov.en” and trafficViolationMain.jsp is in domain “services.www.gov.en”.

2. Code “<iframe src=” http//services.www.gov.qa/TrafficViolationsWeb/trafficViolationMain.jsp”></iframe>” is in the InvokeEService.jsp for load eservice page.

3. “services.www.goc.en” is an eservice from customer side So we can’t change anything on trafficViolationMain.jsp
Requirement
Dynamic adjust iframe’s height and width based on the content of iframe for not show scroll bar of iframe.

Code Changed
1. changed the root domain by execute javascript “document.domain=www.gov.en” which locate in “InvokeEService.jsp” for InvokeEService.jsp and trafficViolationMain.jsp can communicate with each other.
“iframe.style.height = iframe.contentWindow.document.body.scrollHeight;” in “onload” event of iframe.

What happen
1. There is a main menu displays complete in the page when we visit http://stg.www.gov.en/InvokeEService.jsp,It can display complete

2. click one link in above page
the bottom of the content in iframe lost.

Analysis

It caused by javascript exception when the program execute to “iframe.style.height = iframe.contentWindow.document.body.scrollHeight;”.

So I did test as below

1. execute javascript “alert (iframe.contentWindow);” It prompt a dialog and displays “[object]”
2. execute javascript “alert (iframe.contentWindow.document);” Nothing happened but there is a javascript error occurred .The error message is “Access is denied”

Based on the above test result .I think the problem is iframe cross domain visit.
Please help me if you can resolve this issue.Thank you very much.




...全文
151 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
llfengend 2009-06-24
  • 打赏
  • 举报
回复
because you have changed domain both two page,you can put the codes which thrown exception in a try catch block,when the iframe page load finished, the codes can be run normally
shenhongsh 2009-04-29
  • 打赏
  • 举报
回复
我也是这么想的,看了很多的解决方案,基本上都是需要可以改写iframe加载的那个页面的内容才能实现跨域访问。但是这种eservice的没办法,郁闷啊。
阿云ivan 2009-04-29
  • 打赏
  • 举报
回复
目前主流的浏览器都是禁止js跨域访问的
所以,没法解决!

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧