Iframe highly adaptive solution for webpage access in file Mode

Source: Internet
Author: User

Recently, the highly adaptive problem of iframe was solved. I searched a lot of solutions on the internet, and I tried these solutions one by one. Finally, I found that they didn't work in my projects, later, I found that my webpage was accessed through file. I put the webpage code under apache and accessed it through http. When loading iframe, I called the following js method:
Copy codeThe Code is as follows:
<SPANstyle = "FONT-FAMILY: KaiTi_GB2312; FONT-SIZE: 18px"> functionSetWinHeight (obj)
{
Varwin = obj;
If (document. getElementById)
{
If (win &&! Window. opera)
{
If (win. contentDocument & win. contentDocument. body. offsetHeight)
Win. height = win. contentDocument. body. offsetHeight;
Elseif (win. Document & win. Document. body. scrollHeight)
Win. height = win. Document. body. scrollHeight;
}
}
} </SPAN>

Sure enough, the webpage is highly adaptive (for other solutions, I did not pay attention to trying it out), but when I access the webpage through file, the same code log always reports: unsafew.criptattempttoaccessframewithurlfile: /// E:/workspace/html5/exam.html from
FramewithURLfile: // E:/workspace/html5/quiz_preview.html.
Domains, protocolsandportsmustmatch.
This error is reported in each solution. It can only be solved from this problem. Later, it was found that this cross-origin access through file method chrome is not allowed by default, check how to set chrome to allow cross-origin access: the simplest method is to right-click the chrome icon and add '-- disable-web-security' to the property-> target'

Restart chrome to open the page to be called. The problem is fixed.

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.