[MS CRM 2016 On Prem] Why does responding to browser requests with JavaScript in an IFrame work in IE but no other browser?

Sending
User Review
0 (0 votes)

First things first, I am not a webdev by trade but I do know enough to be able to develop little iframe widgets and extensions for our on-prem dynamics CRM system. Please forgive me if I am missing something obvious here.

(TL;DR at bottom)

This is going to take a bit of background to understand what is going on. Without getting too specific we have an entity in dynamics CRM that has an embedded iframe with a button. The entity page itself (parent page) has some fields we pass to the iframe (child) using javascript that looks something like this:

function Form_onload() { var iframe = Xrm.Page.ui.controls.get("IFRAME_MyIFrame"); var myVar1 = Xrm.Page.getAttribute("new_myvar1").getValue(); var url = "https://crm.mycompany.com:8443/MyIframe/MyIframe.aspx?myVar1=" + myVar1; iframe.setSrc(url); } 

This is pretty simplified and has the identifying bits chopped out but to explain what is going on, IFRAME_MyIframe is the identifier in CRM for the IFrame, Xrm is the CRM SDK for JavaScript, and new_myvar1 is the name of the field in CRM we are grabbing a value from. This loads the iframe which has a button on it which looks more or less like this (again, stripped down to what is necessary for context):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyIframe.aspx.cs" Inherits="CRM_Web_Application.MyIframe.MyIframe" %> <!DOCTYPE html> <head> <title>MyIframe 1.0</title> </head> <body> <form id="form1" runat="server"> <p>Some Text Here</p> <asp:Button ID="Button1" OnClick="MyCSharpFunction" Text="Do Something" runat="server" /> <div id="info" runat="server"> <p>Output:<asp:Label ID="out" runat="server" /></p> </div> </form> </body> 

When the button is clicked it runs MyCSharpFunction() which will take the variable passed in the URL, do something to it, then return the output both to the IFrame and to a field in the parent page. This is accomplished by doing this:

using System.Web.UI; //skip some class and namespace definitions protected void MyCSharpFunction(object sender, EventArgs e) { string myVar1 = Request.QueryString["myVar1"]; string outVar1 = DoSomething(myVar1); Response.Write("<scri" + "pt language='javascript'>"); Response.Write("document.parentWindow.parent.Xrm.Page.getAttribute('new_myout1').setValue('" + outVar1 + "');"); Response.Write("</scrip" + "t>"); out.Text = outVar1; } 

So this whole charade works perfectly with IE, both the label "out" in the iframe and the field "new_myout1" in the parent window are updated with the correct output. Looking at the network tab of the dev tools in IE vs Chrome I can see in IE that a POST is sent to the server when the button is pressed and soon after the browser receives a GET and updates the page as expected. However in Chrome/FireFox I can see the POST is sent but no GET is ever received and neither the iframe nor the parent page are ever updated.

TL;DR: IFrame POSTs to server, server takes variable, does something to it, and uses Response.Write() to send back a pair of <script> tags which contain JavaScript update info on the parent page. IE will send the POST and receive a GET with the script just fine. Chrome/Firefox will only send the POST, no sigh of a GET and the page does not update.

Does anyone know whats up here? Am I missing something?

submitted by /u/BrowsingFromWork117
[link] [comments]