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


How can I modify the contents of one web page from another?

让我解释一下我的问题,我有一个包含文本区域的页面"a"。我的页面"a"上有一个调用脚本的按钮,这个脚本会打开一个包含页面"B"的弹出窗口。

如何将"A"页上的内容从"B"页更改?

例如,检索文本区域并在其中插入一些内容?(无数据库)

谢谢!

build 2 html页面:test.htm和popup.htm-test.htm将打开popup.htm,现在如果您在弹出窗口(文本区域)中输入内容并按下按钮,文本将发送到test.htm文本区域…:

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>

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

如何访问子窗口的dom树?