언어 설정

Menu
Sites
Language
Usage of JavaScriptBridge--Anybody has success !!

HI,

I am stuck to send data from my html file to the c++ file and vice-versa. I have followed the guiding instruction given in the below link:

https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Ftutorials%2Fweb_tutorial%2Fusing_javascriptbridge.htm

But I am not able to succeed.

When tried with the above link code, here is the error i am getting:

ERROR / Tizen::Web::Controls ( 12258 : 12258 ) : Tizen::Web::Controls::IJavaScriptBridge* Tizen::Web::Controls::_WebImpl::FindJsInterface(const Tizen::Web::Json::IJsonValue*) const(3519) > [E_OBJ_NOT_FOUND] Propagating.
ERROR / Tizen::Web::Controls ( 12258 : 12258 ) : virtual result Tizen::Web::Controls::_WebImpl::OnHandleJavaScriptRequestByEventArg(const Tizen::Base::Runtime::IEventArg&)(4215) > [E_OBJ_NOT_FOUND] JsInterface instance is not available.
------------------------
to summarise my requirement :
1. I have an .html file in data folder.
2. I have an web control class ( derived from Tizen::Web::Controls) through which i am loading the html .
3. I am doing some operation in my c++ files which needs to be updated in my web view. For that i need some way to intimate my js in html file. And once that is done, need to communicate back to c++.
-----------------------

Any help or code snippet much appreciated.

Thanks in advance.

Edited by: Brock Boland on 17 3월, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

11 댓글
Kotofei
Have you added your JavaScriptBridge to your web control?
newbee
hi, Are you referring to add this in .html file ? --- then i've added this.
Kotofei
Not exactly. Did you use that method: result Tizen::Web::Controls::Web::AddJavaScriptBridge (const IJavaScriptBridge & jsBridge) ? It adds JavaScript bridge instance to your control.
newbee
You are bang on:).. How can i missed the listener to add ??... Thanks, You saved my time..
Nikolay Syedin
I added listener, but got the same errors. Any ideas? Thanks.
basu
Hi Nikolay, I've used javascriptbridge successfully in my app. Can you let me know what are the steps you have done or some code snippet that will help to guide you further.
Nikolay Syedin
Hi basu, Thank you very mutch for you reply. I do nearly the same as described in https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Ftutorials%2Fweb_tutorial%2Fusing_javascriptbridge.htm: 1) target html file is: < !DOCTYPE HTML > < html > < head > < object id = "Tizen" type = "application/x-tizen-jsbridge" width = "0" height = "0" > < /object > < script type = "text/Javascript" > function Hello() { Tizen.requestToNative("{\"name\":\"MyJsBridge\", \"data\":\"hello\"}"); } < /script > < /head > < body > This is JavaScriptBridge interface test page < form > < input type="button" value="Send Data" onclick="Hello()"/ > < /form > < /body > < /html > 2) Form with Web control inherited from IJavaScriptBridge: class NewsLetterForm : public Tizen::Web::Controls::IJavaScriptBridge ... 3) realization of 2 abstract methods: virtual Tizen::Base::String GetName (){ return Tizen::Base::String(L"JavaScriptBridge"); } virtual void HandleJavaScriptRequestN(Tizen::Web::Json::IJsonValue *pArg){ result r = E_SUCCESS; JsonObject* pJsonObject = static_cast< JsonObject* >(pArg); IJsonValue* pValue = null; JsonString* pJsonStringValue = null; String key(L"data"); r = pJsonObject->GetValue(&key, pValue); pJsonStringValue = static_cast< JsonString* >(pValue); AppLog("data: %ls\n", pJsonStringValue->GetPointer()); } The errors are the same as above: 09-12 15:12:07.212 : ERROR / Tizen::Web::Controls ( 2566 : 2566 ) : Tizen::Web::Controls::IJavaScriptBridge* Tizen::Web::Controls::_WebImpl::FindJsInterface(const Tizen::Web::Json::IJsonValue*) const(3504) > [E_OBJ_NOT_FOUND] Propagating. 09-12 15:12:07.212 : ERROR / Tizen::Web::Controls ( 2566 : 2566 ) : virtual result Tizen::Web::Controls::_WebImpl::OnHandleJavaScriptRequestByEventArg(const Tizen::Base::Runtime::IEventArg&)(4152) > [E_OBJ_NOT_FOUND] JsInterface instance is not available.
basu
Can you please check if you have added this in your .cpp file __pWeb->AddJavaScriptBridge(*this) // where __pWeb is instance of Web().
Nikolay Syedin
Yes sure, i added it on NewsLetterForm::OnInitializing: web->AddJavaScriptBridge(*this);
basu
Can you please refer to this reference application and check: https://developer.tizen.org/documentation/articles/use-tizen-native-apis-google-map-display-route
Nikolay Syedin
The problem was in my inattention function Hello() { Tizen.requestToNative("{\"name\":\"MyJsBridge\", \"data\":\"hello\"}"); } irtual Tizen::Base::String GetName (){ return Tizen::Base::String(L"JavaScriptBridge"); } After i substitute MyJsBridge on JavaScriptBridge in Hello() everything is ok