Case: In the MinAn system, iFrame is used to include a third-party (another domain) page. The two systems are deployed on the same machine. The homepage of iFrame is a logon interface, on the page where iFrame is located, use a script to obtain the content of the logon interface, assign values to the username and password fields, and submit them for automatic login. However, if you use http: // IP: port to access the system, this function is normal. If you use http: // localhost: port to access the system, a script error is prompted: access is denied.
Baidu, probably because the src content of iFrame is http: // IP: port, so when you access the system through http: // localhost: port, the browser believes that the script code for automatic login is operating on the Content of another domain, and thus the access is denied, which is the security mechanism of the browser.
I wanted to change the src value in iFrame Based on the URL: http: // IP: port or http: // localhost: port. However, no matter which method is used to obtain the iframe. when src is assigned a value, access is denied. Instead, you have to use jsp code to obtain the URL and assign the value iFrame. src
- <%
- String path = request. getContextPath ();
- String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
- String vSrc = "";
- If (basePath. indexOf ("localhost")>-1 ){
- VSrc = "http: // localhost: 8080/teamserver ";
- } Else {
- VSrc = "http: // 192.168.62.55: 8080/teamserver ";
- }
- %>