1

Similar to how <iframe>, <embed>, <object> etc are used to embed external videos, plugins etc into websites, is it possible to directly embed an application into Blazor? Presumably a .NET application would be easier.

Something like

<div>

    <application path="/dist/file/myApplication.exe"></application>

</div>

Looking at the capabilities of Web Assembly, I'm certain the general concept is achievable. I just wonder if there's a way to do it easily in Blazor.

Upate for clarification:

My original question wording was perhaps too simplistic. I don't necessarily mean that literally <application path="myApplication.exe"></application> would do the trick. What I'm really thinking about is the concept of a user-friendly way to embed a non-Javascript application into a website, via WASM. I mentioned Blazor because it seems to be the current best contender for offering an easier way to do this.

Here's what inspired this question: https://webassembly.org/demo/Tanks/

I figured that since a Unity game has been successfully ported to run in Web Assembly on the browser, it might be possible to do similar with any application (within reason).

Perhaps not now, but in a not-too-distant future.

7
  • Most likely not. What would the application take as input and output in such a case? Commented Apr 28, 2019 at 6:12
  • 1
    @SamiKuhmonen I'm not sure what you mean. The thing that inspired this question is the following example - webassembly.org/demo/Tanks - which is basically an application embedded into a website (though I'm not sure if it was made using .Net or C++). I'm wondering if this kind of thing might be possible via Blazor, if not now then perhaps in the future. Commented Apr 28, 2019 at 6:39
  • I mean if you just take a random executable how would it interact with anything? Applications at least have output, would it just put stdout to the web page? Input? Graphical UIs? And if it’s not a .NET application it would need to be converted to something either wasm or .NET can handle. Commented Apr 28, 2019 at 6:45
  • 1
    Unity games were able to be played in browser way before blazor. You have to compile it certain way Commented Apr 28, 2019 at 7:48
  • @FCin Yeah I'm aware of that. The main point for me is that an application was ported/converted into web assembly for running in a browser. It stands to reason that there should be a way to do this with many other kinds of application. It wouldn't necessarily have to be done via Blazor, I just figured it might be something worth considering. Commented Apr 28, 2019 at 7:54

1 Answer 1

1

If you have something that is "Hosted on the web" you can embed it "inside" a Blazor app using code like this:

    <script type="text/javascript">
    // From: https://gomakethings.com/getting-html-asynchronously-from-another-page/
    var getHTML = function (url, callback) {
        // Feature detection
        if (!window.XMLHttpRequest) return;
        // Create new request
        var xhr = new XMLHttpRequest();
        // Setup callback
        xhr.onload = function () {
            if (callback && typeof (callback) === 'function') {
                callback(this.responseXML);
            }
        };
        // Get the HTML
        xhr.open('GET', url);
        xhr.responseType = 'document';
        xhr.send();
    };
    </script>

    <script type="text/javascript">
    var populateDiv = function (element) {
        getHTML('https://blazor.net/', function (response) {
            element.innerHTML = response.documentElement.innerHTML;
        });
    };
    </script>

ElementRef modalBody; // reference to the DIV
protected override void OnAfterRender()
{
  // This will set the content of the Div
  // to the content of the server Login page
  setDivContent(modalBody);
}
    
public Task setDivContent(ElementRef elementRef)
{
   return JSRuntime.InvokeAsync<object>("populateDiv", elementRef);
}
<div ref="modalBody" class="modal-body">
<!-- Dynamic content will go here -->
</div>

See: Razor Components Popups and JavaScript Interop

Sign up to request clarification or add additional context in comments.

2 Comments

I think this is the reverse of what I was asking. Your code looks like Javascript interop for performing standard website style Javascript actions on a Blazor site. What I hoped for was a way to plonk .NET applications (or any application) into a Blazor site.
Yes and so is the code of half the applications on the Windows Store. I was asking if (and I know it's a big "if") it would be possible to get generic applications like that to run in Blazor. Nothing to do with Javascript interop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.