无法在交叉起源上发布消息

发布于 2025-02-03 00:15:16 字数 999 浏览 3 评论 0原文

我有以下代码,并尝试发布消息,但在A< input>中获取阻止自动关注的。跨原生蛋白子帧中的元素。错误。

import React from 'react'
const MyFiles = () => {
    React.useEffect(() => {
        let frame = document.getElementById('storage')
        frame.contentWindow.postMessage({user: 'admin', password: 'blahblah'}, '*');

    }, []);
    return (
        <React.Fragment>
       
            <div className="pt-100 pb-70">
                <div className="container">
                  <iframe id='storage' src='https://my.domain.com' style={{width: '100%', height: '100vh'}}/>
                </div>
            </div>
        </React.Fragment>
    )
}

export default MyFiles

到底是怎么回事?

这是否过时 SecurityError:阻止了一个框架,该框架无法访问跨原始框架

I have the below code and trying to post a message but get a Blocked autofocusing on a <input> element in a cross-origin subframe. error.

import React from 'react'
const MyFiles = () => {
    React.useEffect(() => {
        let frame = document.getElementById('storage')
        frame.contentWindow.postMessage({user: 'admin', password: 'blahblah'}, '*');

    }, []);
    return (
        <React.Fragment>
       
            <div className="pt-100 pb-70">
                <div className="container">
                  <iframe id='storage' src='https://my.domain.com' style={{width: '100%', height: '100vh'}}/>
                </div>
            </div>
        </React.Fragment>
    )
}

export default MyFiles

What is going on?

Is this out of date SecurityError: Blocked a frame with origin from accessing a cross-origin frame?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩套路吗 2025-02-10 00:15:16

我认为发布消息没有什么关系,我的错误是在使用效率上而不是on load上这样做:

const post = () => {
    try{
        let frame = document.getElementById('storage')
        frame.contentWindow.postMessage({user: 'name', password: 'pass'}, storageUrl);
        console.log('posted')
        } catch (e){
            console.log(e)
        }
}
return (
    
        <div className="pt-100 pb-70">
            <div className="container">
            <iframe id='storage' src='https://my.domain.com' style={{width: '100%', height: '100vh'}} onLoad={post}/>
            </div>
        </div>
)

Figured the error had nothing to with posting a message, my mistake was doing it on useEffect instead of an onload:

const post = () => {
    try{
        let frame = document.getElementById('storage')
        frame.contentWindow.postMessage({user: 'name', password: 'pass'}, storageUrl);
        console.log('posted')
        } catch (e){
            console.log(e)
        }
}
return (
    
        <div className="pt-100 pb-70">
            <div className="container">
            <iframe id='storage' src='https://my.domain.com' style={{width: '100%', height: '100vh'}} onLoad={post}/>
            </div>
        </div>
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文