Hi,
I have a web page with a iFrame. I do not own the host page but I need to assign the host web page title to the same value as the title of that iFrame each time it is has loaded.
When I create my own fake host page as follow:
Code: HTML/ASPX
<iframe src="https://prime.aa.com/prime/prime.html" name="hostedAppFrame" id="hostedAppFrame" onload="document.title = document.getElementById('hostedAppFrame').contentDocument.title;">
Browser does not support iFrame. Please contact your administrator.
</iframe>
It works just fine, however the real host page does not have a
onload defined in its iframe element.
So in my code, when the host page has loaded, I'm trying to redefine dynamically the
onload handler by executing the following script:
Code: C#
ExecuteScript("document.getElementById('hostedAppFrame').onload=\"document.title = document.getElementById('hostedAppFrame').contentDocument.title;\"", out res)
FYI... I execute this javascript using this code - it works very well for all the other scripts I execute.
Code: C#
public override bool ExecuteScript(string script, out object result)
{
result = null;
object res = null;
bool success = false;
try
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
lock(webView)
{
JSScriptHander jshdl = new JSScriptHander(script);
if (webView.CanEvalScript)
{
ScriptCall myCall = webView.QueueScriptCall(jshdl.Call);
if (myCall.WaitOne(1000))
{
if (!myCall.IsAborted && myCall.IsDone)
{
res = myCall.Result;
success = true;
}
}
}
}
}));
}
catch (EO.WebBrowser.JSException jse) {
}
catch (Exception e) {
}
result = res;
return success;
}
At runtime, once the call has executed,
result is an instance of a
string of value:
"document.title = document.getElementById('hostedAppFrame').contentDocument.title;"So I assume it worked, however next time my
iFrame changed, hence the onload event has been triggered, nothing happens.
I am almost positive my problem is not in the way I execute the javaScript but rather in a misunderstanding of how much I can actually re-assign dynamically event handlers such as the onload of a iFrame.
Any idea?
Thanks a lot in advance!