<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p></p>
<div>I have a webpage that has an iframe inside and I want to add an event handler to hidden element inside iframe<br>
<br>
I have the following code<br>
<br>
static void load_status_frame_cb(GObject* object, GParamSpec* pspec, gpointer data) {<br>
std::cout << "load_status_frame_cb" << std::endl; <br>
}<br>
<br>
void update_iframe(WebKitDOMElement *element, WebKitDOMEvent *dom_event, gpointer context){<br>
std::cout << "updateIFrame" << std::endl;<br>
}<br>
<br>
static void load_status_cb(GObject* object, GParamSpec* pspec, gpointer data) {<br>
<br>
WebKitWebView *web_view;<br>
WebKitLoadStatus status;<br>
WebKitDOMDocument *dom;<br>
WebKitDOMElement* hidden;<br>
<br>
web_view = WEBKIT_WEB_VIEW(object);<br>
status = webkit_web_view_get_load_status(web_view);<br>
<br>
switch (status) {<br>
case WEBKIT_LOAD_PROVISIONAL:<br>
break;<br>
case WEBKIT_LOAD_COMMITTED:<br>
break;<br>
case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:<br>
break;<br>
case WEBKIT_LOAD_FINISHED:<br>
dom = webkit_web_view_get_dom_document(web_view);<br>
<br>
WebKitWebFrame * frame = webkit_web_frame_find_frame (webkit_web_view_get_main_frame(web_view),"frame_name1");<br>
g_signal_connect(frame, "notify::load-status", G_CALLBACK(load_status_frame_cb), frame);<br>
//WebKitDOMDocument * frame_dom = webkit_web_frame_get_dom_document (frame);<br>
//hidden = webkit_dom_document_get_element_by_id (frame_dom,"hidden_id1");<br>
//bool res = webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET (hidden), "change", G_CALLBACK (updateIFrame), false, GINT_TO_POINTER(i));<br>
//if (res == true){<br>
// std::cout << "TRUE" << std::endl;<br>
//}else{<br>
// std::cout << "FALSE" << std::endl;<br>
//}<br>
break;<br>
<br>
case WEBKIT_LOAD_FAILED:<br>
break;<br>
<br>
default:<br>
break;<br>
}<br>
}<br>
<br>
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.<br>
<br>
In any way the callback functions are not called (`load_status_frame_cb` for the first way and `update_iframe` for the second way)<br>
<br>
In the second way `webkit_dom_event_target_add_event_listener` return true<br>
<br>
The source webpage is (for the main page)<br>
<br>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br>
<html xmlns="http://www.w3.org/1999/xhtml"><br>
<head><br>
<br>
<title></title><br>
</head><br>
<body style="border: 1px solid silver;"><br>
<iframe src="test.php" frameBorder="0" name="frame_name1"></iframe></body><br>
</html><br>
<br>
and the source for the iframe is:<br>
<br>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br>
<html xmlns="http://www.w3.org/1999/xhtml"><br>
<head><br>
<title></title><br>
</head><br>
<body style="border: 1px solid silver;"><br>
<input type="hidden" id="hidden_id1" name="hidden_3" value="0"></body><br>
</html><br>
<br>
What is wrong?</div>
<br>
<p></p>
</div>
</body>
</html>