tags:

views:

273

answers:

1

Hi

I have a WPF WebBrowser which loads a HTML page with vbScript functions on it from intranet I want to execute one of these functions and retrieve the return value.

Unfortunately I have no ability to change the the intranet page

The function returns a boolean value and is as follows

Function IsAltered(strMode)

' This procedure checks to see if Changes have been made without saving.
Dim objItem, blnIsAltered
IsAltered = False
blnIsAltered = False

For Each objItem In window.document.all
 If (objItem.tagName = "INPUT" And objItem.className <> "Lbl" And objItem.className <> "NAF" And objItem.className <> "PreDispNoChange") Or _
    objItem.tagname = "SELECT" Or objItem.tagname = "TEXTAREA"  Then
  If Left(objItem.Id, 3) <> "hid" And objItem.Type <> "hidden" And objItem.Style.Visibility <> "hidden" Then
   If HasValueChanged(ObjItem.Id, Trim(objItem.Value)) Then
    blnIsAltered = True
    Exit For
   End if
  End If
 End If
Next
IsAltered = blnIsAltered   End Function

Can somebody suggest a way of implementing this

Thanks

Regards

Col

A: 

System.Windows.Controls.WebBrowser has a method called InvokeScript, which, according to the documentation "Executes a script function that is implemented by the currently loaded document."

You might want to try that.

kmontgom
I have tried using this but there are two issues 1) I am getting the following error messsage "Unknown name. (Exception from HRESULT:0x80020006 (DISP_E_UNKNOWNNAME))"2) there is a return of void on invokeScript so I can't check if the function returns true or false?ThanksColm
Colmdoc
Apparently there are some issues with the WPF WebBrowser control.See the StackOverflow issue regarding differences between the WPF and WinForms versions (see margin).You may want to switch over to the WinForms version of WebBrowser. Don't forget that it is relatively easy to embed WinForms components in WPF. That way you get complete access to the HTML DOM.
kmontgom
thanks I'll try that and get back to you
Colmdoc
After discussion with the team it has been decided to not replace the WPF webBrowser with Winforms one due to time constraints. I found a work around to this issue by using the IHTML class's to cehck if html page was altered from the wPF application logic. I'm curious if there is an update to the WPF web browser in the pipeline?
Colmdoc
I guess that we will have to wait until this spring, when .NET 4/WPF 4 will be released...
kmontgom