Welcome Guest Search | Active Topics | Sign In | Register

Target iFrame with Evalscript Options
Ioannis
Posted: Monday, May 23, 2016 12:07:31 PM
Rank: Newbie
Groups: Member

Joined: 5/13/2016
Posts: 5
After I set the following code...

Quote:
Dim options As New EO.WebEngine.BrowserOptions
options.EnableWebSecurity = False
EO.WebBrowser.Runtime.SetDefaultBrowserOptions(options)


I would like to inject some javascript listeners and functions into an iFrame. I know how to do this in the parent URL, but not an iFrame. How can I do this?

Here is my VB.NET code used for the parent:


Quote:
Dim myScript As String = readJSFile("injectJavascript.js")
WebView1.EvalScript(myScript)


Private Function readJSFile(ByVal fileName As String) As String

readJSFile = Nothing

If File.Exists(fileName) Then

readJSFile = vbCrLf

For Each line As String In File.ReadLines(fileName)
readJSFile = readJSFile & line & vbCrLf
Next

End If
End Function


injectJavascript.js FILE CONTENTS:
document.onclick = function(e) {
//DO SOMETHING...
}
eo_support
Posted: Monday, May 23, 2016 12:11:58 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,068
Hi,

The easiest way to inject JavaScript into all frame is to set WebView.JSInitCode. That way it will be automatically run for all frames (main frame and iframe). If you must use WebView.EvalScript, then you you will need to use the main frame's EvalScript to inject script into the iframe, which means:

Step 1: You use EvalScript to inject some script code into the main frame;
Step 2: JavaScript injected in step 1 runs in the main frame to inject some other script into the iframe.

The second is pure JavaScript and it would not have anything to do with EO.WebBrowser.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.