any simple examples i want ? thanks in advance.
views:
182answers:
2thanks for ur reply. i think "myVariable" is function name, if i correct, how to pass variable to it.If it is variable how to call my function?
Kumar
2009-12-10 05:11:52
I'd imagine window.opener.$(myVariable) would work too.
cxfx
2009-12-10 05:12:08
maybe you need window.opener.myFunction(someVariable)
cxfx
2009-12-10 05:14:00
exactly, but how to define "myFunction(somevariable)" in parent window jquery.
Kumar
2009-12-10 05:17:14
function myFunction(somevariable) { /* like this? */ }
cxfx
2009-12-10 05:19:50
Fine, i tried, but in the function i wrote some jquery line. that is not working, so i want to know when parent window onload completes, how to find that is the question now?
Kumar
2009-12-10 06:50:59
+1
A:
opener is a reference to the window
object of the opening document. I.e. you have access to the global javascript namespace of the opening window.
e.g.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script type="text/javascript">
function foo(url) {
// if there is a reference to the opening window
if (null!=opener) {
// we call the function in the context of the opening window
opener.foo(url);
}
else {
// otherwise show the data
$('#d1').html(new Date() + " : " + url);
}
}
</script>
</head>
<body>
<div id="d1">...</div>
<button onclick="window.open('?');">new window</button>
<button onclick="foo(document.URL);">propagte url</button>
</body>
</html>
if you press "propagate url" in a (in any) popup window the function call will bubble up to the first non-popup window (having opener=null).
edit: keep in mind that security restrictions (like cross domain checks) implemented in the browser apply.
edit2: example with history.go(0)
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script type="text/javascript">
function foo() {
var context = (null!=opener) ? opener : window;
context.history.go(0);
}
$(document).ready( function() {
$('#d1').html("document ready at "+ new Date());
});
</script>
</head>
<body>
<div id="d1">...</div>
<button onclick="window.open('?');">new window</button>
<button onclick="foo(document.URL);">...and action</button>
</body>
</html>
VolkerK
2009-12-10 05:25:27
Thank you. just add "opener.history.go(0);" before "opener.foo(url);" , now it is not working ( for me), any suggestions.
Kumar
2009-12-10 06:49:06
yes, i am changing some of the main-window content in the popup, so i want it to reload with edited contents, and used history.go(0) for restoring the same page view as before.
Kumar
2009-12-10 07:58:38
I think i may need when the main window reloading completes,so that i can call the jquery in it(main window). i tried with window.parent.onload=function_name; but it did't worked. any other way?
Kumar
2009-12-10 08:01:44
Fine, after "context.history.go(0)" i want to execute some function. like "opener.foo(url);" . that fn. not working.after reloads. any ideas to check the completion of parent window reloading.
Kumar
2009-12-10 08:20:34
Now that's an interesting question. I somehow doubt you can use $(opener.document).ready() for that, though I haven't tested it. If it doesn't work you should open another question on _that_ specific matter.
VolkerK
2009-12-10 15:31:03