Javascript 在弹出窗口中编写js脚本

Javascript 在弹出窗口中编写js脚本,javascript,html,Javascript,Html,我正在尝试将js脚本添加到我打开的弹出窗口中,但这样做有困难 这是我的密码: function openGame() { gameWindow = window.open("", "gameWindow", "top=500, left=500, height=988, width=1263"); gameWindow.document.write('<html><head>') gameWindow.document.write('<lin

我正在尝试将js脚本添加到我打开的弹出窗口中,但这样做有困难

这是我的密码:

function openGame() {
    gameWindow = window.open("", "gameWindow", "top=500, left=500, height=988, width=1263");
    gameWindow.document.write('<html><head>')
    gameWindow.document.write('<link rel=\"stylesheet\" href=\"cssbutton.css\">')
    gameWindow.document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"sbg_style.css\">')
}
// at this point I would like to add the following script
$(document).ready(function(){
    $("#checker0").click(function(){
        $("div").animate({left: '250px', top:'250px'});
    });
});

如何做到这一点?

这是为您准备的模板:

var gameWindow = window.open("", 
    "gameWindow", 
    "top=500, left=500, height=988, width=1263");    // external/pop-up window
gameWindow.document.write('<div id="checker">+++++++++</div>');   // example html element
// adding a listener to the element on a external/pop-up window
// there is extended notation for jQuery selector
$("#checker", gameWindow.document).click(function(e){ // listener of element on a external window
  // example of manipulation on a "#checker" div
  $(e.target).text("---------"); // there you can do anything with elements on external window
});

演示:

这是为您准备的模板:

var gameWindow = window.open("", 
    "gameWindow", 
    "top=500, left=500, height=988, width=1263");    // external/pop-up window
gameWindow.document.write('<div id="checker">+++++++++</div>');   // example html element
// adding a listener to the element on a external/pop-up window
// there is extended notation for jQuery selector
$("#checker", gameWindow.document).click(function(e){ // listener of element on a external window
  // example of manipulation on a "#checker" div
  $(e.target).text("---------"); // there you can do anything with elements on external window
});

演示:

它不工作!我使用Google Chrome,当我检查页眉部分的页面时,我看不到listener元素代码。我添加了演示。您可能忘了将所有代码包装在$document中。readyfunction{…}您的示例非常好!!告诉我,我正在尝试设置div的动画,但它不起作用。而不是:$e.target.text---;我做:$'div'。动画{左:'50px'};知道为什么吗?好的,明白了!我所要做的就是用e.target而不是div.@Shvalb:是的!现在,您可以从父窗口代码控制器执行任何操作。甚至为它们创建新节点和侦听器。这不起作用!我使用Google Chrome,当我检查页眉部分的页面时,我看不到listener元素代码。我添加了演示。您可能忘了将所有代码包装在$document中。readyfunction{…}您的示例非常好!!告诉我,我正在尝试设置div的动画,但它不起作用。而不是:$e.target.text---;我做:$'div'。动画{左:'50px'};知道为什么吗?好的,明白了!我所要做的就是用e.target而不是div.@Shvalb:是的!现在,您可以从父窗口代码控制器执行任何操作。甚至为它们创建新的节点和侦听器。