Javascript跨窗口交互 [英] Javascript cross window interaction

查看:182
本文介绍了Javascript跨窗口交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在链接被点击时,我有一个非常简单的JavaScript在文本区域写:

 < head& 
< script language =javascripttype =text / javascript>
function addtext(text){document.form.textarea.value = document.form.textarea.value + = text;}
< / script>
< / head>

< body>
< form action =method =name =form>
< textarea name =textarearows =cols =wrap =wrap>< / textarea>
< / form>
< a href =javascript:addtext('q');> q< / a>
< / body>

现在我想提高注意力。



我想要做的是在另一个窗口中的形式,当我单击链接,我写到另一个窗口中的textarea。



m不一定要求代码,因为我意识到这可能是相当复杂。



问题是从哪里开始,因为我没有一个线索!
(当我使用Javascript交叉窗口或跨域交互时,我真的没有什么有用的东西。)



所以任何帮助我可以得到,

解决方案

好,我给你写了一个样例,你可以检查 http://jsfiddle.net/zzdAL/

  $(document).ready(function()
{
popup = window.open(http://fiddle.jshell.net);
$ #input1)。click(function(){
try {
popup.document.window.alert(1);
}
catch(e){alert .message);}
});
}
);

它只在弹出窗口上运行一个警报,但你可以做任何你想要的弹出窗口,假设你有必要的权利(需要是我相信的相同的域)。



最简单的是在弹出窗口中编写一个函数并从开启者调用它。 / p>

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.

解决方案

Ok, I wrote you a sample you can check at http://jsfiddle.net/zzdAL/

$(document).ready(function()
                  {
                      popup = window.open("http://fiddle.jshell.net");
                      $("#input1").click(function() {
                          try {
                                popup.document.window.alert(1);
                          }
                          catch (e) { alert(e.message); }
                      });
                  }
                 );

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.

这篇关于Javascript跨窗口交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆