Javascript function call from XPCOM, C ++

My goal is to catch pageloads in my component, insert some javascript into the document, and then catch the onFocus events. In the event, I then need to call the javascript function that I inserted.

Now I have managed to solve most of the problems, I have a script added to all web pages and I can catch onfocus events. What they failed to do was execute the javascript function from my XPCOM component (C ++). In my Internet Explorer BHO, I use execScript and it works fine. Any ideas?

My current workaround is to use setattribute and set the onfocus event of each input element to execute the javascript function, but this is intrusive and overwrites existing onFocus handlers on the web page. Other ideas are welcome.

Thanks.

+3
source share
2 answers

If you have a script added to all web pages, the script can take care of registering the "focus" event logger and take appropriate action when the focus event occurs.

I'm not sure why you need to call JS content from your component.

If you need to do this, write down what you have already tried and how it "does not work."

+1
source

, (pre FF6?), . FF6 , javascript . https://support.mozilla.org/en-US/questions/876916

java script URL javascript:alert('hello');

OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus) {
  // check for correct state - document load complete...
  nsCOMPtr<nsIDOMWindow> domWin;
  nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWin));

  nsCOMPtr<nsIWebNavigation> nav = do_GetInterface(domWin);
  if (nav)
    hr = nav->LoadURI(url, 0, 0, 0, 0);
0

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


All Articles