Reputation: 1933
I'm trying to add js script into a popup I opened but having trouble doing so.
Here is my code:
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'});
});
});
How to do this?
Upvotes: 1
Views: 2565
Reputation: 3872
This is a template for you:
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
});
DEMO: http://jsbin.com/qotaxoguvi/1/
Upvotes: 5