[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

Simple javascript function help

I am using a simple function on the onclick of a hyperlink
 
<li><a href="javascript:cliedit()">Client Edit</a></li>

Open in new window


This opens an edit record page.   When I close that page I want another function (gogetit)  to execute. gogetit is currently running before the next page closes.  Gogetit does an ajax update.
function cliedit()
{
var cs=document.getElementById("conno").value;
var urlstring="?cSearch="+cs;
open("https://www.myvcaccount.com/cgi-bin/upclient.exe"+urlstring , "", "toolbar=no,menubar=no,width=800,height=425,resizable=no");
gogetit(cs);}

Open in new window


So how do I get it to run after I close the page.

Thanks
]
0
Charlietn
Asked:
Charlietn
  • 3
  • 2
1 Solution
 
experts1Commented:
Below is example of parent and child windows, where closing child window will  
return focus to parent window.

Code for PARENT window below:
<html>
<head>
<title>Close Child Window Show Parent</title>
<script language="javascript">
  var main_win;
function win_child()
{
//var cs=document.getElementById("conno").value;
//var urlstring="?cSearch="+cs;
main_win=window.open("child_window.html", "myWin", "toolbar=no,menubar=no,width=800,height=425,resizable=no");
main_win.focus();
//gogetit(cs);
}
</script>
</head>
<body>
<br>
<input type=button value="Child_Screen" onClick="win_child()">
<br>
<input type=button value="Child_Focus" onClick="javascript:main_win.focus();">
</body>
</html>

Code for CHILD window below:

<html>
<head>
<title>Child_Window</title>
<script language="javascript">
 window.onbeforeunload = function() {
   window.opener.focus();
   alert('onunload event');
}

 function showParent() {
   window.opener.focus();
}
</script>
</head>
<body onunload=" window.opener.focus();">
<br>
<input type=button value="Show_Parent" onClick="showParent()">
<br>
</body>
</html>
0
 
CharlietnAuthor Commented:
I am sorry but I don't follow this.  Is this correct

var main_win;
function win_child()
{
var cs=document.getElementById("conno").value;
var urlstring="?cSearch="+cs;
main_win=window.open("https://www.myvcaccount.com/cgi-bin/upclient.exe"+urlstring , "Client Data", "toolbar=no,menubar=no,width=800,height=425,resizable=no");
main_win.focus();
gogetit(cs);
}

Open in new window

0
 
experts1Commented:
Correct!

This function will open the child window object "main_win" and
ensure that focus is set on the said child window "main_win".

Sorry, my the choice of name should have been "child_win",
but you may change it if you wish.
0
 
experts1Commented:
Just to follow-up:

Maybe you might want to include the "gogetit(cs)" function
on the child window page and execute the "gogetit(cs)" function
within the said child window "onbeforeunload" function instead as follows:

<script language="javascript">
 window.onbeforeunload = function() {
   window.opener.focus();
   //alert('onunload event');
 gogetit(cs);
}

function gogetit(x) {
   // Blah...blah !
  // Do whatever Ajax crazy stuff etc.. !
}

Of coures you would remove the "gogetit(cs)" function call
from the parent window.
0
 
CharlietnAuthor Commented:
Thank you
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now