0

I'm trying to migrate a piece of code from plain JavaScript to Aurelia, and I can't seem to figure out the following code (executed from within a view-model):

var callbackFunction = 'DmsToWorkflowsCallback';
var treeEnum = new BrowseTreeNodeEnums();
var contentType = treeEnum.Document;
var url = dmsUrlPrefix + 
          "BrowseDlgEx.aspx?" + 
          "multiSelect=1" + 
          "&title=Attach" + 
          "&callback=" + callbackFunction + 
          "&contentType=" + contentType + 
          "&context=btworkflows;" + domain;
window.open(url, "_blank", "height=600, width=800,status=0,toolbar=0,menubar=0,location=no,modal=1,dialog=yes,top=100,left=100");

In plain JavaScript, the calling window (which is a custom plugin with no documentation) was able to locate the callback function (line 1) and execute the rest of the business logic correctly; in Aurelia, however, it doesn't seem able to locate the provided function!

I tried specifying the callback function both inside and outside the class (using regular function declaration), as well as using this.DmsToWorkflowsCallback as the callback function specification, without success...

I even tried adding a dummy callback function inside the View using a <script> tag, but still couldn't even get a break-point to hit!

If anyone has any suggestions I would greatly appreciate it!

ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110
Themos
  • 430
  • 1
  • 9
  • 18
  • What does your Aurelia code look like? – Ashley Grant Mar 27 '17 at 15:12
  • @AshleyGrant I'm calling the above code from a simple Aurelia click.delegate="..." function in my ViewModel, and what I'm trying to do is catch the window.open's returning callback. – Themos Mar 29 '17 at 06:36
  • Maybe this will help: http://stackoverflow.com/questions/2797560/set-a-callback-function-to-a-new-window-in-javascript – Ashley Grant Mar 29 '17 at 22:13

1 Answers1

0

You just need to set the callback function on the window object. If the function you want to call is a function on your VM, then it would be best to wrap the call in a fat arrow function:

window.theCallback = () => this.theCallback();
window.open('http://localhost:9000/foo.html', '_blank');

Then, in the child page, you'll call this function using the opener reference.

opener.theCallback();
Ashley Grant
  • 10,879
  • 24
  • 36
  • To add a comment, this question is really a duplicate of http://stackoverflow.com/questions/25098573/how-to-call-parent-window-function-from-child-window-jquery (even though no jQuery is used here). That answer says to use `window.parent`, but I wasn't able to get that to work. Only `window.opener` worked. – Ashley Grant Mar 30 '17 at 14:22