How to create interaction with two windows in JQuery
L.S.
Excuse me if my english isn't very good. I try to make it as understandable as possible. For the last couple of weeks I've been looking for a solution to have some kind of interaction between two windows in a web application. I want to play an animation in the first window and when it plays I want to open a new window with controls to stop it. (The purpose of all this is that I want to play the animation on my first display and the animation controls on my second, but that is not of high importance). I know that there is a window.opener thing in JQuery but I've tried to implement that a couple of times and that did not work. I hope someone can help. This will be appreciated very much! This is how far i've got now:
$(function test() { /* Assign a name to this window (index.html)*/
window.name = "main"; /*When the button test is clicked */
$("#test").click(function test() { /*check if the window name works */
alert(window.name); /* This works! */
/*Open a second window, source is controlpanel.html, window name is control */
var control = window.open("controlpanel.开发者_开发技巧html", "control");
});
/*When button test 2 is clicked*/
$("#test2").click(function() { /* change the color of the control window */
$(control).css('background-color', '#9900FF'); /*This does not work */
});
});
Launch the control window from the primary window then you can address the primary window from the secondary widow using...
window.parent.document
You can also use the opener to do this
If you open you secondary window with javascript in the secondary window you can call "function1" in the primary window like so.
window.opener.document.function1();
See this example of exactly what you are trying to do: http://www.javascriptkit.com/javatutors/remote2.shtml
control is not a selector
$(control).css('background-color', '#9900FF');
CSS needs to know where to apply the background. Your selector should either be a tag, id, or class ex: $('div')
or $('#myid')
or $('.myclass')
. Control as you have it in your code is none of those.
精彩评论