如何从另一个网页修改一个网页的内容?

时间:2012-07-10 14:57:19

标签: php javascript jquery html

让我解释一下我的问题,我有一个包含textarea的页面“A”。 我的页面“A”上有一个调用脚本的按钮,此脚本会打开一个包含页面“B”的弹出窗口。

我怎样才能在页面“B”的页面“A”上更改某些内容?

例如检索textarea并在其中插入一些东西? (没有数据库)

谢谢!

2 个答案:

答案 0 :(得分:1)

这是一个很好的SO答案,非常相关(并使用jQuery)。基本上,您想要操纵子窗口的DOM(由当前窗口打开的窗口):

How can I access the dom tree of child window?

答案 1 :(得分:1)

构建2个html页面:test.htm和popup.htm - test.htm将打开popup.htm,现在如果你在弹出窗口中输入内容(textarea)并按下按钮,文本将被发送到test .htm textarea ...:

test.htm

<h1>Page A<h1>
<form name="frm">
    <textarea name="txt"></textarea>
    <button onclick="popup('popup.htm')">Open Popup</button>
</form>


<script type="text/javascript">
    function popup (url) {
        win = window.open(url, "window1", "width=600,height=400,status=yes,scrollbars=yes,resizable=yes");
        win.focus();
    }
</script>

popup.htm:

<h1>Page B</h1>

<form name="frm">
<textarea name="txt"></textarea>
<button onclick="window.opener.frm.txt.value=document.frm.txt.value">Update Site A</button>
</form>