我不知道你会如何将JavaScript注入别人的页面,然后别人会向你发送消息。这听起来像是病毒会做的事情。
I think you could accomplish something like what you want using an iframe.
A simple method would be to include an iframe preset to load the “start” location on your site, and then include a button on the outer page for the user to post back their current location (in the iframe).
When the button on your page is pressed you could query the current state of the iframe…
References to the window generated by the iframe and to the document loaded into the iframe can be obtained via the frames array using the name attribute.
window.frames[iframeName] <br/>
window.frames[iframeName].document <br/>
引用的frames数组方法得到了广泛的支持,即使在相当旧的浏览器中也是如此,只要将name属性附加到iframe即可。为了获得最佳效果,请同时使用名称和id。
对于更新的浏览器,还可以通过iframe元素的contentWindow(IE win)和contentDocument(DOM)属性引用iframe中的文档:
// IE5.5+ windows
document.getElementById(iframeId).contentWindow
document.getElementById(iframeId).contentWindow.document
or,
// DOM
document.getElementById(iframeId).contentDocument
编辑:正如下面的评论所示,看起来大多数浏览器都会阻止你以这种方式使用iframe。你可以在你想要的地方启动一个窗口,但如果它不在你的同一个域上,你就不允许与它通信。我想你可以构建一个“中间人”场景,首先通过服务器传输所有流量,但这并不实用。
下面是jQuery控制iframe的一个很好的例子
http://wwwendt.de/tech/dynatree/doc/sample-iframe.html
希望能有所帮助。