JS Access Denied Error

Source: Internet
Author: User

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

 

  1. <%
  2. String path = request. getContextPath ();
  3. String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
  4. String vSrc = "";
  5. If (basePath. indexOf ("localhost")>-1 ){
  6. VSrc = "http: // localhost: 8080/teamserver ";
  7. } Else {
  8. VSrc = "http: // 192.168.62.55: 8080/teamserver ";
  9. }
  10. %>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.