Javascript跨窗口交互
当单击链接时,我有一个非常简单的 Javascript 可以在文本区域上写入:
<head>
<script language="javascript" type="text/javascript">
function addtext(text) {document.form.textarea.value = document.form.textarea.value+= text;}
</script>
</head>
<body>
<form action="" method="" name="form">
<textarea name="textarea" rows="" cols="" wrap="wrap"></textarea>
</form>
<a href="javascript:addtext('q');">q</a>
</body>
现在我想提高赌注。
我想做的是将表单放在另一个窗口中,当我单击链接时,我会写入另一个窗口中的文本区域。
我不一定要代码,因为我意识到这可能相当复杂。
问题是从哪里开始,因为我没有线索! (当我用 Javascript 进行跨窗口或跨域交互时,我并没有真正得到任何有用的东西)。
因此,我可以获得的任何帮助、库、插件或任何可能引导我走向正确方向的东西都非常值得赞赏。
I have this very simple Javascript to write on a text area when the link is clicked:
<head>
<script language="javascript" type="text/javascript">
function addtext(text) {document.form.textarea.value = document.form.textarea.value+= text;}
</script>
</head>
<body>
<form action="" method="" name="form">
<textarea name="textarea" rows="" cols="" wrap="wrap"></textarea>
</form>
<a href="javascript:addtext('q');">q</a>
</body>
Now I want to up the ante.
What I want to do is have the form in another another window, and that when I click the link, I writes to a textarea in another window.
I'm not necessarily asking for the code because I realize this might be quite complicated.
The question would be where to start, because I haven´t got a clue!!
(when I Google cross window or cross domain interaction with Javascript I don't really get anything useful).
So any help I can get, libraries, plugins or whatever might guide me in the right direction is more than appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,我给你写了一个示例,你可以在 http://jsfiddle.net/zzdAL/ 查看
它只运行弹出窗口上有一个警报,但是您可以对弹出窗口执行任何您想做的操作,前提是您拥有必要的权限(我认为需要是同一域)。
最简单的方法是在弹出窗口中编写一个函数并从打开器中调用它。
Ok, I wrote you a sample you can check at http://jsfiddle.net/zzdAL/
It only runs an alert on the popup, but you can do whatever you want with the popup, assuming you have the necessary rights (needs to be the same domain I believe).
The most simple is to write a function in your popup and call it from the opener.
可能已经太晚了,但这里有一个交互示例:窗口交互
Probably it's too late, but here is an example of interaction: window interaction
看看greasemonkey,它是您浏览器的插件。
您可以选择脚本将在哪些页面上运行。
http://wiki.greasespot.net/Main_Page
Take a look to greasemonkey, it's an addon for your browser.
You can choose on which page(s) the script will works.
http://wiki.greasespot.net/Main_Page