iframe cross domain communication
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.