Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically open new browser tab with Silverlight and set content
    primarykey
    data
    text
    <p>Was wondering if there is any way in Silverlight to open a new browser tab and set its content. In short, my app receives files (binary data) and needed to have the user's browser presenting them. </p> <p>My app downloads contents (images/pdfs/whatever) from repositories from the cloud and stores them as binary data in a local cache; then after that I need a way to display those now local contents to the end user in a new tab. The "new tab" requirement is due to silverlight not supporting rendering of many file types such as .gif, .pdf and others - things that browsers handle easily, either natively or with widely used plugins. So my current WTF-y solution uses System.Windows.Browser and consists in the following:</p> <pre><code> // Get document and body var doc = HtmlPage.Document; var body = doc.Body; // Create a &lt;form&gt; element and add it to the body var newForm = doc.CreateElement("form"); newForm.SetAttribute("action", "www.example.com/contentpresenter.php"); newForm.SetAttribute("enctype", "multipart/form-data"); newForm.SetAttribute("method", "POST"); newForm.SetAttribute("target", "_blank"); body.AppendChild(newForm); var inp = doc.CreateElement("input"); inp.SetAttribute("type", "text"); inp.SetAttribute("name", "mcontent"); inp.SetAttribute("value", Tools.ToBase64( content.Content as Stream )); newForm.AppendChild(inp); var inpt = doc.CreateElement("input"); inpt.SetAttribute("type", "text"); inpt.SetAttribute("name", "tcontent"); inpt.SetAttribute("value", content.ContentType); newForm.AppendChild(inpt); // Send away! newForm.Invoke("submit"); </code></pre> <p>In short, it creates a javascript script that posts the content to a remote PHP script which in turn does nothing more than decoding and presenting the content, which will open in a new tab. Yes, I'm fully aware of how idiotic it sounds - but does the trick and works as intended. </p> <p>As far as I know, creating a new HtmlWindow and building up/altering its contents is not an option due to security constraints. An obvious option is having Silverlight produce javascript which would in turn create a new tab that loads the provided content, but javascript is not too big in handling binary or base64 data - at least not cross-browser seamlessly - and the whole thing seems stupid anyways. </p> <p>Is there a solution to achieve this solely through Silverlight, or at least with a minimum amount of javascript involved? Alternatively, is there any javascript library you would recommend to handle base64 data?</p> <p>Best regards!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload