使用easyXDM修改provider页面内容

发布于 2024-12-26 10:16:33 字数 1325 浏览 2 评论 0原文

我正在尝试使用 easyXDM javascript 库来实现一些跨域黑客。

easyXDM 的一些背景知识。我们有两个角色:

  1. 提供者,提供供其他人调用的函数
  2. ;消费者,调用提供者提供的函数。

需求是这样的:

The consumer passes the content as parameter and calls the function through RPC. 
The provider receives the request and use the content to modify its page.

这里,修改其页面意味着尝试修改DOM结构或DOM节点中的内容。

provider 端的代码,一旦消费者请求,它将修改其页面内容。

var provider = new easyXDM.Rpc({}, {
    local: {
        modifyContent: {
            method: function(content){
                // modify the content on my page
            }
        }
    }
});

消费者端,将执行RPC来要求提供者更改其页面。

    var consumer = new easyXDM.Rpc({
        remote: "remoteUrl"
    }, {
        remote: {
            modifyContent: {}
        }
    });
    //perform RPC and ask the provider to the modify its content
    consumer.modifyContent("This is some content that should be used to modify your content");

一切都进展顺利,除非提供者尝试使用内容来修改其页面。

不会引发任何错误或警告。但页面不会按预期改变。

此外,我单独运行“更改内容”代码(例如在 Firebug 控制台或 Chrome 控制台中复制并粘贴并运行),它会起作用。

有人使用过easyXDM并遇到过这个问题吗?

PS:easyXDM这里似乎不是一个标签。如果您认为值得的话,请为我添加它。

I am trying to use easyXDM javascript library to achieve some cross domain hack.

Some background on easyXDM. We have two roles:

  1. the provider, which provides the function to be called by others
  2. the consumer, which calls the function provided by provider.

The requirement is like this:

The consumer passes the content as parameter and calls the function through RPC. 
The provider receives the request and use the content to modify its page.

Here, modifying its page means trying to modify the DOM structure or the content in the DOM node.

The code for the provider side, which will modify its page content once requested by the consumer.

var provider = new easyXDM.Rpc({}, {
    local: {
        modifyContent: {
            method: function(content){
                // modify the content on my page
            }
        }
    }
});

The consumer side, which will perform RPC to ask the provider to change its page.

    var consumer = new easyXDM.Rpc({
        remote: "remoteUrl"
    }, {
        remote: {
            modifyContent: {}
        }
    });
    //perform RPC and ask the provider to the modify its content
    consumer.modifyContent("This is some content that should be used to modify your content");

All things go on well excepts when the provider tries to use the content to modify its page.

No errors nor warnings are raised. But the page just won't change as expected.

Besides, I run the "change content" code alone(like copy&paste&run in Firebug console or Chrome console), it will work.

Has anyone used easyXDM before and encountered this problem?

PS: easyXDM seems not to be a tag here. Please add it for me if you agree it deserves.

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

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

发布评论

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

评论(1

爱冒险 2025-01-02 10:16:33

我遇到了同样的问题,问题是我不明白 easyXDM 的 RPC 功能是如何工作的。

对我来说,问题是我将子 iframe 添加到父 iframe,然后使用添加到页面的 iframe 的 url 调用 easyXDM.Rpc() 。当我从父级向子级发送消息时,子级会很好地接收该消息(并且控制台会记录正确的消息),但我无法更改子 iframe 中的任何本地内容或全局变量。我不明白的是,当在父级中创建新的 RPC 客户端时,该工具会自动创建 iframe。我以为它只会使用我在页面上绘制的 iframe。因此,我从一个 iframe(默认情况下绘制在屏幕外)进行日志记录,并与未连接到 RPC 调用的 iframe 进行交互。

为了解决这个问题,我删除了添加到页面的 iframe,并使用 RPC 配置的“props”属性使 iframe 在屏幕上可见。一旦我这样做了,一切就顺利了。

I ran into the same issue, and the problem was that I didn't understand how easyXDM's RPC functionality worked.

The problem for me was that I was adding the child iframe to the parent and then calling easyXDM.Rpc() with the url of the iframe I added to the page. When I would send a message from the parent to the child, the child would receive the message just fine (and console log the correct message) but I was not able to change any local content or global variables in the child iframe. What I didn't understand is that when a new RPC client is created in the parent that the tool automatically creates an iframe. I thought that it would just use the iframe that I painted on the page. So I was logging from one iframe (which by default is painted off screen) and interacting with an iframe that wasn't wired to the RPC call.

To fix the problem, I removed the iframe that I had added to the page and used the "props" property of the RPC config to make the iframe visible on the screen. Once I did that, everything worked well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文