I need to be able to work out what page is hosting my silverlight app. I can get the url of the iframe using System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsolutePath
, but I want to get the URL of the web page hosting the iframe.
System.Windows.Browser.HtmlPage.Document.DocumentElement.Parent
is null.
Thanks!
Well somebody gave me a link but their answer has since disappeared? Cheers whoever it was! :)
This is the way I did it:
MainPage.xaml.cs:
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
HtmlPage.RegisterScriptableObject("Page", this);
HtmlPage.Window.Invoke("GetParentURL");
}
[ScriptableMember]
public void GetParentURL(string result)
{
if (result.IndexOf("WhatIamLookingFor") > 0)
imgLink.Visibility = Visibility.Visible;
else
imgLink.Visibility = Visibility.Collapsed;
}
Default.aspx:
<script type="text/javascript">
function GetParentURL() {
var control = document.getElementById("silverlightControlHost");
control.children[0].Content.Page.GetParentURL(parent.location.href);
}
</script>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="/ClientBin/MyApp.Silverlight.xap"/>
<param name="background" value="transparent" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<param name="windowless" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
<iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With