Page 1 of 1

ExecuteScript question

Posted: Tue May 16, 2017 7:43 pm
by Aracknid
Hi,

I have a feature in my web app that can appear within its own Window (thus its own WebDocument) or within an IFrame of its parent window.

I've written a bunch of code in my framework to handle getting some variable info from my web app's WebDocument object using ExecuteScript. It works fine when its in its own WebDocument, but fails when embedded in the IFrame.

I realize why, because I'm using code like this:
StrValue = MyWebDocObj.ExecuteScript("return MyVar;")
And of course when embedded in the IFrame, it isn't looking at that.

So, I can also do this:
If Embedded then
    StrValue = MyIFrameObj.ExecuteScript("return MyVar;")
Else
    StrValue = MyWebDocObj.ExecuteScript("return MyVar;")
End if
But I have a lot of places with executescript calls, and what I'd really like to do is make it more generic so that it will work without a condition. Is it possible to do this?

For example:
StrValue = MyGeneralObj.ExecuteScript("return MyVar;")
Where MyGeneralObj works for either a WebDocument or an IFrame.

Thanks,

Aracknid

Re: ExecuteScript question

Posted: Wed May 17, 2017 11:27 am
by RobinHood42
Hi,

the easiest way would be to add a new class like:

Code: Select all

Public NotInheritable Class MyGeneralObj
	Private Sub New()
	End Sub
	Public Shared Function GetVar(Embedded As Boolean) As String
		If Embedded Then
			Return MyIFrameObj.ExecuteScript("return MyVar;")
		Else
			Return MyWebDocObj.ExecuteScript("return MyVar;")
		End If
	End Function
End Class
and replace all your calls to

Code: Select all

StrValue = MyWebDocObj.ExecuteScript("return MyVar;")
with

Code: Select all

StrValue = MyGeneralObj.GetVar(Embedded)
hth