Home  >  Article  >  Web Front-end  >  Iframe highly adaptive solution when accessing web pages in file mode_javascript skills

Iframe highly adaptive solution when accessing web pages in file mode_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:43:361029browse

Recently, I have solved the problem of highly adaptable iframes. I searched for many solutions on the Internet, but in summary, there are only a few. I tried these solutions one by one, and finally found that none of them worked in my project. Later I found that I did The web page is accessed through the file method. Put the web page code under apache and access it through the http protocol. When the iframe is loaded, call the following js method:

Copy code The code is as follows:

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;
}
}
}

Sure enough, the height of the webpage can be adapted (it should also be effective for other solutions, I didn’t pay attention to try it), and the same code log for accessing the webpage through the file method is always in the log Report: UnsafeJavaScriptattempttoaccessframewithURLfile:///E:/workspace/html5/exam.htmlfrom
framewithURLfile:///E:/workspace/html5/quiz_preview.html.
Domains, protocols and ports must match.
Each solution The error reported when I tried was this. I could only solve this problem. Later I found that cross-domain access via file is not allowed by Chrome by default. I also checked how to set Chrome to allow cross-domain access: the simplest method. Right-click on the chrome icon, properties-> add '--disable-web-security' after the target

Restart chrome and open the web page you want to adjust, and the problem is solved
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn