The IFRAME height adaptive solution _javascript tips when accessing Web pages in file mode

Source: Internet
Author: User
Recently to achieve an IFRAME highly adaptive this problem, a lot of online search solutions, and summed up on those several, I try these programs, and finally found that in my project did not work, and later found that they do the Web page is accessed by file way, Put the web page code under Apache access through the HTTP protocol, when the IFRAME load call the following JS method:
Copy Code code 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, page height can be adaptive (for other programs should also have effect, I did not pay attention to try), and file access to the Web page the same code log always reported: Unsafejavascriptattempttoaccessframewithurlfile :///e:/workspace/html5/exam.htmlfrom
Framewithurlfile:///e:/workspace/html5/quiz_preview.html.
Domains,protocolsandportsmustmatch.
Every solution tries to report the wrong is this, can only be solved from this problem, and later found that this way through file Cross-domain access is not allowed by default, and how to set the Chrome allow Cross-domain access: The simplest way in the Chrome icon right button, attribute-> After the target is added '--disable-web-security '

Restart Chrome to open the page you want to tune, the problem is solved

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.