在来自不同域的iframe中运行Meteor应用程序

前端之家收集整理的这篇文章主要介绍了在来自不同域的iframe中运行Meteor应用程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
经过几周的工作,我现在终于准备好部署我的应用程序,只是为了发现流星似乎没有运行在iframe中.当顶级窗口和iframe在同一个域上运行时,它的运行正常,但域不同时. Chrome的错误是:
  1. Uncaught SecurityError: Access to 'sessionStorage' is denied for this document.@H_404_3@
  2. 在这个错误之后,Meteor的初始化似乎停止了,甚至Meteor本身也不会被定义.

  3. 经过一番挖掘,我发现了这个参考和解释:http://www.w3.org/TR/webstorage/#user-tracking
    :“阻止第三方存储
    用户代理可以将localStorage对象限制为源自浏览上下文顶层文档域的脚本,例如拒绝访问来自其他ifframe中的域的页面API.

  4. 问题不是我的应用程序的特定.您可以在流星图库中使用任何演示应用程序,并尝试将它们嵌入到另一个带有iframe页面中,您将看到我的意思.

  5. 有没有办法解决

  6. 编辑2014-01-07
    我尝试过在try-catch块中抛出异常的地方,但是有一个令人印象深刻的是流星太多了,因为它不会由于不同的原因进行正确的初始化.

解决方法

我无法重现您遇到的具体问题,但这里是为了使其正常运行而遵循的步骤.也许我们可以从那里解构出来,弄清楚错误是什么.

我创建了一个空白的应用程序:

meteor create testapp

那么我添加了浏览器策略模块:

meteor add browser-policy

然后我编辑了testapp.js,使其使用Session:

  1. if (Meteor.isClient) {
  2. Template.hello.greeting = function () {
  3. return Session.get( 'welcome_text' );
  4. };
  5.  
  6. Template.hello.events({
  7. 'click input' : function () {
  8. // template data,if any,is available in 'this'
  9. if (typeof console !== 'undefined')
  10. console.log("You pressed the button");
  11. Session.set( 'welcome_text','Hello: ' + Math.random() );
  12. }
  13. });
  14. }
  15.  
  16. if (Meteor.isServer) {
  17.  
  18. BrowserPolicy.framing.allowAll();
  19.  
  20. Meteor.startup(function () {
  21. // code to run on server at startup
  22. });
  23. }@H_404_3@
  24. 我创建了两个@R_404_196@虚拟主机:

  25. server {
  26.     listen 80;
  27.     server_name test1.com;
  28.     location / {
  29.         proxy_pass http://127.0.0.1:3000/;
  30.         proxy_http_version 1.1;
  31.         proxy_set_header Upgrade $http_upgrade;
  32.         proxy_set_header Connection "upgrade";
  33.     }
  34. }
  35. server {
  36.     listen 80;
  37.     server_name test2.com;
  38.     location / {
  39.         alias /websites/test2.com
  40.     }
  41. }@H_404_3@ 
  42.  

    test1是流星应用,test2iframe.

  43.  

    对于test2,我创建了/websites/test2/index.html

  44.   
  45.  
    <iframe src="http://test1.com">@H_404_3@ 
  46.  

    然后我将test1.comtest2.com添加到我的主机文件,并启动了流星应用程序.

  47.  

    我在浏览器上进入了http://test2.com,一切都按预期运行.您似乎已经尝试过这些步骤,但您的应用程序或服务器堆栈可能有其他组件干扰浏览器策略.

  48.  

    我将从更新您的问题开始,以包含流星应用的请求和响应标头.您的流星应用程序是否在代理服务器后面运行?

猜你在找的HTML相关文章