语言

Menu
Sites
Language
How to receive result data from webkit with javascript?

Hello,

I using EFL webkit with javascript.

I already knew that EFL provide function to execute javascript "ewk_view_script_execute".

But, I don't know how can use it.

Can you show me some example, please?

Thank you.

响应

6 回复
colin Rao

Hi,

I also don't call this api in practice. But as its api description on the IDE help doc. Seems it's easy to understand, as below:

the parameter "script" is the real script sentence, it can be the function name. And you can get the result of function/sentence executing in the callback function,

as below api description, "result_value" should be the returned value of js function/sentence.

Eina_Bool ewk_view_script_execute  ( Evas_Object *  o,  
  const char *  script,  
  Ewk_View_Script_Execute_Cb  callback,  
  void *  user_data  
 )   

Requests the execution of the given script. 
Since :2.3Remarks:This allows to use NULL for the callback parameter. So, if the result data from the script is not required, NULL might be used for the callback parameter.Parameters:
[in] o         The view object to execute the script  
[in] script    The JavaScript to execute  
[in] callback  The result callback  
[in] user_data The user data 
Returns:EINA_TRUE on success,otherwise EINA_FALSE 
typedef void(* Ewk_View_Script_Execute_Cb)(Evas_Object *o, const char *result_value, void *user_data) 

Callback for ewk_view_script_execute(). 
Since :2.3Parameters:
[in] o            The view object  
[in] result_value The value returned by the script  
[in] user_data    The user_data will be passsed when ewk_view_script_execute() is called  

 

Kim

Thank you for your answer.

I tested using below code.

void
test_cb(void *data, Evas_Object *obj, void *event_info)
{
    ...
    const char scripts[]="return 'test';";
    Evas_Object *ewk = ewk_view_add(evas_object_evas_get(nf));
    Ewk_Settings *settings = ewk_view_settings_get(ewk);
    ewk_settings_javascript_enabled_set(settings, EINA_TRUE);
    ewk_view_script_execute(ewk, scripts, scriptCallback, NULL);
    ...
}

void scriptCallback(Evas_Object *obj, const char *result_value, void *user_data) {
    dlog_print(DLOG_DEBUG, "myTag", "scriptCallback %s %s", (char *)result_value, (char *)user_data);
}

But the result is always (null).

I searched works to use "ewk_view_script_execute" function, I saw some developer has similar result.

Is it a bug?...

Thack you.

 

Kim

return \"test\" is same result.

Kim

Code fixed

 

void scriptCallback(Evas_Object* o, const char* result_value, void* user_data) {
    dlog_print(DLOG_DEBUG, "myTag", "scriptCallback %s", result_value);
}

void cb_test(){
    const char scripts[]="return \"test\"";
    void (*cb_test)(Evas_Object*, const char*, void*) = scriptCallback;
	ewk_view_script_execute(ewk, scripts, cb_test, NULL);
}

 

colin Rao

Hi,

I can get the return value, sample code as below, 

static void
scriptCallback(Evas_Object *obj, const char *result_value, void *user_data) {
    dlog_print(DLOG_INFO, LOG_TAG, "[scriptCallback] return value: %s\n", result_value);
}

static Evas_Object*
test_ewk_view_script_execute(appdata_s *ad)
{
    /* Naviframe */
    ad->naviframe = elm_naviframe_add(ad->conform);
    evas_object_size_hint_weight_set(ad->naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(ad->naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_show(ad->naviframe);

    Evas_Object *ewk = ewk_view_add(evas_object_evas_get(ad->naviframe));
    Ewk_Settings *settings = ewk_view_settings_get(ewk);
    ewk_settings_javascript_enabled_set(settings, EINA_TRUE);
    ewk_view_script_execute(ewk, "function test() { return 'test'; }; test();", scriptCallback, NULL);

    elm_naviframe_item_push(ad->naviframe, "ewk_view_script_execute", NULL, NULL, ewk, NULL);
    return ad->naviframe;
}

log:

09-11 14:32:06.357 : INFO / test ( 10067 : 10067 ) : [scriptCallback] return value: test

 

Kim

THANK YOU!!!!! :) IT WORKS!!!