【问题标题】:How to put something inside new opened window using jQuery如何使用 jQuery 在新打开的窗口中放置一些东西
【发布时间】:2011-12-28 14:10:46
【问题描述】:

我有 2 个文件。 current.htmnew.htm

我在current.htm 中使用window.open() 打开其他文件并为新文件指定了一个名称。

现在,我需要在 new.htm 的某个部分添加一些文本(例如 <div>)。

我怎样才能用 jQuery 做到这一点?

【问题讨论】:

  • 所以,你想动态修改一个子窗口的DOM。
  • 感谢 Shark 的编辑。是的,我只需要使用 jQuery 就可以了。我这里所说的只是我真实项目的一部分。

标签: jquery window.open


【解决方案1】:

您所做的是使用window.opener 拉动更改,如此处所示http://forum.jquery.com/topic/how-do-i-manipulate-a-dom-in-an-window-open

编辑解释:

current.htm 的脚本块中,您可以:

function editChild() {
    // Do stuff with DOM here.
}

new.htm中:

$(document).ready(function() {window.opener.editChild(); } );

希望这会有所帮助。

【讨论】:

  • 我认为你是对的;但是链接不是答案,所以请在您的帖子中添加解释:)
  • 不错的一个。现在很好回答。 :)
【解决方案2】:

如果您想修改子窗口的 DOM,请尝试以下操作

$(childWindow.document).ready(function() { 
   var $theDiv = $(childWindow.document).contents().find('#yourdiv');
   // $theDiv.WhateverYouWantToDo();
}); 

【讨论】:

    【解决方案3】:

    为什么不直接将<script> ... </script> 放入new.htm 以动态编辑文本?还是我错过了什么?

    【讨论】:

    • 很确定他想从父母那里做。
    • 解释我认为某人试图做的事情从来都不是我的强项;D
    • 有时会很困难;这当然也不例外!
    【解决方案4】:

    在 new.htm 中:$("div#myDiv").html("This is some text").

    【讨论】:

    • 很确定他想从父母那里做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多