iframe和页面处在不同域下,iframe操作页面的属性与方法

iframe和页面处在不同域下,iframe操作页面的属性与方法

问题来源:

当iframe和父页面处在不同域下,会因为跨域造成限制,拿不到父页面的大多数属性与方法

解决方案:

通过代理页面解决跨域问题

1、在父页面中设置一个sessionStorage

http://localhost:3333/public/index.html




    
    
    
    Document


    父页面
    



2、然后在父页面同一域下新建一个agent.html页面

http://localhost:3333/public/agent.html




    
    
    
    Document


    代理页面



3、最后在iframe页面中创建一个看不见的iframe来加载这个代理页面

http://localhost:3334/public/index3.html




    
    
    
    Document


    
iframe页面

你可能感兴趣的:(iframe和页面处在不同域下,iframe操作页面的属性与方法)