sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.57k stars 268 forks source link

Create new window can not control by handle for Go, #170

Closed yanyuxuanz closed 5 years ago

yanyuxuanz commented 5 years ago

if I use tiscript to create a new window,then I can't use "view" Object to call go's EventHandler window.DefineFunction();Perhaps I don't know which I have a mistake.. In other words,the main go can only provide handlers for the main window.

pravic commented 5 years ago

You can make a proxy object with required functions and pass it to a newly created window:

Main window:


var API = {
  msgBox: function(args..) { view.msgbox.apply(view, args); },
  nativeCall: function(args..) { view.nativeCall.apply(view, args); },
};

view.window( { 
  type: View.POPUP_WINDOW,
  url: ...,

  parameters: API,  // <-- pass our API to a new window
});

New window:

var API = view.parameters;
API.msgBox(#information, "Hello");
pravic commented 5 years ago

Also a slightly easier approach with global functions via View.funcName (note capital letter - it's a class in opposite to view - the instance (object) of the class): https://sciter.com/forums/topic/how-to-call-the-native-function-from-the-dialog-view/#post-46473

yanyuxuanz commented 5 years ago

aha,Solved the problem, same as you said.Thanks.