I'm trying to set the HTML of an Iframe at runtime, from code behind.
In my aspx page i have:
<asp:Button ID="btnChange" runat="server" Text="Change iframe content"
onclick="btnChange_Click" />
<br />
<iframe id="myIframe" runat="server" />
in the code behind:
protected void btnChange_Click(object sender, EventArgs e)
{
myIframe.InnerHtml = "<h1>Contents Changed</h1>";
}
When i run this.... it posts back, but doesn't change the myIframe contents at all... What am i doing wrong??
I need to do this because im implementing 3D secure into my checkout process.. basically:
1) customer enters credit card details 2) form is submitted, checks with payment gateway if 3d secure is required. if so, url is generated for the banks secure location to enter information 3) i create a POST request to this url, that contains a long security token, and a few other bits of information. i get hold of the HTML returned from this POST request, and need to display it in an iFrame.
Heres what the documentation says to do:
<html>
<head>
<title>Please Authenticate</title>
</head>
<body onload="OnLoadEvent();">
<form name="downloadForm" action="https://mybank.com/vbyv/verify" method="POST">
<input type="hidden" name="PaReq" value="AAABBBBCCCCHHHHHH=">
<input type="hidden" name="TermUrl" value="https:// www. MyWidgits.Com/next.cgi">
<input type="hidden" name="MD" value="200304012012a">
</form>
<script language="Javascript"> <!-- function OnLoadEvent(){ document.downloadForm.target = "ACSframe"; document.downloadForm.submit(); } //--> </script>
<!-- MERCHANT TO FILL IN THEIR OWN BRANDING HERE -->
<iframe src="blank.htm" name="ACSframe" width="390" height="450" frameborder="0">
</iframe>
<!-- MERCHANT TO FILL IN THEIR OWN BRANDING HERE -->
</body>
</html>
Answers. use the below Javascript to set ifame inner html .. var doc = document. getElementById('IframeId');
Open the topic with the IFrame in it. Right-click the IFrame element, and from the context menu, select Edit IFrame. From the Insert IFrame dialog, do any of the following: Edit Source field Update the URL that you want to display in the IFrame window.
According to CodePen's Chris Coyier, which uses cross-origin iFrames for every customer, “For now, even the cross-origin removal is delayed until January 2022, but as far as we know this is going to proceed, and then subsequent steps will happen to remove them entirely.
You have to specify a </iframe> closing tag. Self-closing tags ( /> ) don't work. End tags are required. See also: MDN: iFrame.
You can try this:
protected void btnChange_Click(object sender, EventArgs e)
{
myIframe.Attributes["src"] = "pathtofilewith.html"
}
or maybe this will work too:
protected void btnChange_Click(object sender, EventArgs e)
{
myIframe.Attributes["innerHTML"] = "htmlgoeshere"
}
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