Silverlight 3 - Refresh an IFrame
I have an ASP.NET application that has a DIV and an IFRAME. The DIV hosts my Silverlight application. The IFRAME points to another page on my site. When a user clicks a button in my Silverlight application, I'm trying to set a value in a hidden field on the page in the IFRAME and submit the page.
Currently, I'm calling a JavaScript function in the page that hosts my Silverlight application. I'm trying to use the JavaScript function to then interact with the page in the IFRAME through the HTML DOM. Oddly, whenever I access the document element on the FRAME object, a message is passed back to my Silverlight application that says:
"Type 'slBridge' does not exist. Parameter name: typeName"
Here is the code calling the JavaScript function in my Silverlight application.
HtmlPage.Window.CreateInstance("slBridge", new string[开发者_如何学运维] { });
Here is my JavaScript code:
function slBridge() {
alert("Getting to execute JS");
for (i = 0; i < window.frames.length; i++) {
if (window.frames[i].name == "bridgeIFrame") {
alert(windows.frames[i].document.title); // If I remove this line it works. I can print the value of "i" as well
break;
}
}
}
Is there some security thing that I am not aware of? If so, how do I access an IFrame from my SL application?
Thank you
Dim domelement As HtmlElement = System.Windows.Browser.HtmlPage.Document.GetElementById("iframe")
If domelement.GetStyleAttribute("visibility") = "visible" Then
domelement.SetStyleAttribute("zIndex", "3")
End If
example of changing iframe in dom from SL
I'm not sure why you are using CreateInstance
. To invoke a function use Invoke
:-
HtmlPage.Window.Invoke("slBridge");
精彩评论