[webkit-gtk] How to add event handler to element inside iframe in webkitGTK1?

Ángel Luis Perales Gómez AngelLuisPG89 at hotmail.com
Wed Mar 29 05:54:58 PDT 2017


I have a webpage that has an iframe inside and I want to add an event handler to hidden element inside iframe

I have the following code

    static void load_status_frame_cb(GObject* object, GParamSpec* pspec, gpointer data) {
            std::cout << "load_status_frame_cb" << std::endl;
    }

    void update_iframe(WebKitDOMElement *element, WebKitDOMEvent *dom_event, gpointer context){
        std::cout << "updateIFrame" << std::endl;
    }

    static void load_status_cb(GObject* object, GParamSpec* pspec, gpointer data) {

        WebKitWebView *web_view;
        WebKitLoadStatus status;
        WebKitDOMDocument *dom;
        WebKitDOMElement* hidden;

        web_view = WEBKIT_WEB_VIEW(object);
        status = webkit_web_view_get_load_status(web_view);

        switch (status) {
            case WEBKIT_LOAD_PROVISIONAL:
            break;
            case WEBKIT_LOAD_COMMITTED:
            break;
            case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
            break;
            case WEBKIT_LOAD_FINISHED:
                dom = webkit_web_view_get_dom_document(web_view);

                WebKitWebFrame * frame = webkit_web_frame_find_frame (webkit_web_view_get_main_frame(web_view),"frame_name1");
                g_signal_connect(frame, "notify::load-status", G_CALLBACK(load_status_frame_cb), frame);
                //WebKitDOMDocument * frame_dom = webkit_web_frame_get_dom_document (frame);
                //hidden = webkit_dom_document_get_element_by_id (frame_dom,"hidden_id1");
                //bool res = webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET (hidden), "change", G_CALLBACK (updateIFrame), false, GINT_TO_POINTER(i));
                //if (res == true){
                //  std::cout << "TRUE" << std::endl;
                //}else{
                //  std::cout << "FALSE" << std::endl;
                //}
            break;

            case WEBKIT_LOAD_FAILED:
            break;

            default:
            break;
        }
    }

As you can see, I tried two ways. The first way (uncommented code) is trying to connect a signal to `WebKitWebFrame` returned by `webkit_web_frame_find_frame`. The second way is to try to get the DOM from frame directly (the commented code), then I get the hidden element and attach event handler to it.

In any way the callback functions are not called (`load_status_frame_cb` for the first way and `update_iframe` for the second way)

In the second way `webkit_dom_event_target_add_event_listener` return true

The source webpage is (for the main page)

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>

        <title></title>
        </head>
        <body style="border: 1px solid silver;">
    <iframe src="test.php" frameBorder="0" name="frame_name1"></iframe></body>
        </html>

and the source for the iframe is:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <title></title>
        </head>
        <body style="border: 1px solid silver;">
    <input type="hidden" id="hidden_id1" name="hidden_3" value="0"></body>
        </html>

What is wrong?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-gtk/attachments/20170329/f746c0d7/attachment.html>


More information about the webkit-gtk mailing list