Onclick div or oncontext only works once after loading webview in cocoa

I am currently working on Mac OS X cocoa. I am making one application using web view. In my demo application, I installed two buttons and one webview. Both buttons load the same file. The first time I get a click on the div id, but after the second load of the web view, I don't get the div id. I am using web-kit for an interface method to call the obj-c method from a java script. I have applied many solutions, but I can not track his problem. Please give me a solution as soon as possible. here is the screenshot the first time I clicked div id in the console

I have the code below to implement a web view

<body >
<div  class="xxx">
          <table  class="xxx">
            <tr>
            <td class="xxx"><img alt="userimg" src="sdfasdf.jpg" /></td>
            <td >
                <div class="xxx">
                  <div class="xxx">
                    <div class="msg" id="1" onClick="window.objcConnector.MsgDivClicked_(this.id)" >Hiiiiiiiii</div>
                  </div>
                  <div class="xxx">
                  <div class="xxx" id="2" onClick="window.objcConnector.MsgDivClicked_(this.id)" >Heyy</div>
                  </div>
                  <div class="xxx">
                  <div class="xxx" id="3" onClick="window.objcConnector.MsgDivClicked_(this.id)" >Hello</div>
                  </div>

                  <div class="xxx">Sat,7 Nov.7:38 PM</div>
               </div>

  Objective-c
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
{
if (aSelector == @selector(MsgDivClicked:)) return NO;

return YES;}



 -(void)MsgDivClicked:(id)object
{
NSLog(@"%@ Div Clicked",object);
}
+4

Source: https://habr.com/ru/post/1620345/


All Articles