Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Is there a way to invoke window.onload using Interop inside Blazor Wasm Component

$
0
0

I am trying to create an application which uses Moneris Hosted Payment Solution- basically implementing an iframe which needs to register an event on window on load. It has postmessage api, which when invoked will return a message, and what I can do is register a callback function so I can decode/use those messages.

The problem is I am not sure how can I invoke this window.onload on blazorwasm. I have tried to implement this but at the moment it is not working.

I am sharing my code. Your help would be a lot appreciated.

this is in my Blazor Page.

protected override async Task OnAfterRenderAsync(bool firstRender){    Console.WriteLine("hello test");    if (firstRender)    {        Console.WriteLine("invoking this function");        await JSRuntime.InvokeVoidAsync("MonerisEvents.setWindowOnLoad");    }}

This is my javascript code in wwwroot.

window.MonerisEvents = {    doMonerisSubmit: function doMonerisSubmit() {        var monFrameRef = document.getElementById('monerisFrame').contentWindow;        monFrameRef.postMessage('tokenize', 'https://esqa.moneris.com/HPPtoken/index.php');        //change link according to table above        return false;    },    respMsg : function (e) {        var respData = eval("(" + e.data +")");        console.log(respData);        console.log(respData.responseCode);        console.log(respData.errorMessage);        console.log(respData.bin);        console.log(respData.dataKey);        document.getElementById("monerisResponse").innerHTML = e.origin +" SENT " +" - " +            respData.responseCode +"-" + respData.dataKey +"-" + respData.errorMessage;        document.getElementById("monerisFrame").style.display = 'none';    },    setWindowOnLoad : function setWindowOnLoad()    {        var self = this;        window.onload = function () {            console.log("was here second");            if (window.addEventListener) {                window.addEventListener("message", self.respMsg, false);            }            else {                if (window.attachEvent) {                    window.attachEvent("onmessage", self.respMsg);                }            }        }    } }

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>