cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
gunners6522
Contributor

Browser Control RegisterJSObject window.external.notify

I'm using the Archicad browser control with the "Browser_Control" example. The example project works as intended and javascript can communicate to the browser control through the registered javascript objects from the example ("GetSelectedElements", "AddElementToSelection" and "RemoveElementFromSelection"). Now I have changed the javascript page from the example, to my own webpage that utilizes "window.external.notify" and I want to register a javascript object, so that I can hook up on this event/method. I have issues with this part and can't seem to subscribe or bind to this "external" object. In the example project I have tried to add and register this javascript object in the method "BrowserPallette::RegisterACAPIJavaScriptObject".

 

void BrowserPalette::RegisterACAPIJavaScriptObject ()
{
DG::JSObject* jsACAPI = new DG::JSObject ("external");
jsACAPI->AddItem(new DG::JSFunction("notify", [](GS::Ref<DG::JSBase> param) {
Authentication(GetStringFromJavaScriptVariable(param)); // my own method that I want javascript to trigger.
return ConvertToJavaScriptVariable (true);
}));
browser.RegisterAsynchJSObject(jsACAPI);
}

 

Has anyone tried something similar or maybe have some good ideas I can try? I haven't tried using a CEF browser before so I'm not at all experienced in communicating from javascript to the Archicad browser control. I might be missing something obvious like defining my javascript object wrong, that I want to register with "RegisterAsynchJSObject". 

1 Reply 1
gunners6522
Contributor

Managed to subscribe to window.external.notify this way, if anyone should be interested:

- Changing the name of jsACAPI from "external" to "aarchicad" (could be anything)

- browser.RegisterAsynchJSObject(jsACAPI)

- browser.ExecuteJS(GS::UniString("window.external.notify = aarchicad.notify;"));

 

Then when the webpage calls window.external.notify, the browser gets notified and the function aarchicad.notify gets triggered.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!