Skip to content

测试::iframe跨越高度自适应解决方案才测试,传统的代理页面以及html5解决方案

Notifications You must be signed in to change notification settings

blueforest/iframeCrossDomain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

在跨域问题上,域仅仅是通过“URL的首部”来识别而不会去尝试判断相同的ip地址对应着两个域或两个域是否在同一个ip上. 参考:https://developer.51cto.com/art/201102/245701.htm

一.用代理页面的方法

主页面 www.a.test,嵌套页面:www.b.test 本地apache配置多域名

  • 1.hosts 绑定 127.0.0.1 www.a.test 127.0.0.1 www.b.test
  • 2.apache配置 httpd-vhosts.conf文件配置
<VirtualHost *:80>
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/iframetest/a"
    ServerName www.a.test
   SetEnv RUNTIME_ENVIROMENT DEV
   <Directory "/Applications/XAMPP/xamppfiles/htdocs/iframetest/a">
      Options Indexes FollowSymLinks
      AllowOverride none
      Order allow,deny
      Allow from all         
      RewriteEngine on
      RewriteBase    /
      RewriteCond %{REQUEST_FILENAME}   !-f
      RewriteRule ^(.*)$ index.html [L]
   </Directory>
</VirtualHost>

二. 用html5 的postMessage

被嵌套的页面:www.b.test

if( window.postMessage ){
     var message = document.documentElement.scrollHeight;
    window.parent.postMessage(message,'https://www.a.test')
}

接收消息的页面www.a.test

window.onload = function(){
  if(window.postMessage){
    var reciever = function(e){
      document.getElementById("iframea").height = e.data
    }
    if(window.addEventListener){
      window.addEventListener('message',reciever,false);
    }else if(window.attachEvent){
      window.attachEvent('onmessage',reciever);
    }
  }
}

About

测试::iframe跨越高度自适应解决方案才测试,传统的代理页面以及html5解决方案

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published