【问题标题】:IE not showing <form> tag in the literal textIE 未在文本中显示 <form> 标记
【发布时间】:2011-01-01 13:14:44
【问题描述】:

我在我的页面上使用了一个文字,其中包含一个 html 表单。单击特定链接时会显示此文字,页面上会显示覆盖 div,并在覆盖 div 上显示表单。所有浏览器都可以正常工作并且完全符合预期,但 IE 不会在覆盖 div 上显示任何内容,即覆盖 div 出现但为空。我已经尝试将标签一一添加到文字控件中,以查看究竟是哪个标签导致了问题,结果发现所有内容(HTML 输入控件等)都显示在覆盖 div 上,直到添加了 &lt;form&gt; 标签文字。
如果literal.Text 属性没有&lt;form&gt; 标记,则内容在IE 中也可以正常显示。但问题是我需要在文字中包含这个&lt;form&gt;,因为我必须将数据发布回外部链接。当所有其他浏览器都工作正常时,IE 中可能出现什么问题?

以下是设置时的文字内容:

formSalesForce.Text = "<div style='clear:both'></div><h2 class='sIFR-replaced1' style='text-align:left'><embed height='20'  id='h2heading' width='282' src='frutiger_light.swf' quality='best' flashvars='txt=Document Description&amp;textalign=left&amp;offsetTop=0&amp;textcolor=#878787&amp;hovercolor=#76b404&amp;linkcolor=#87be22&amp;w=282&amp;h=20' wmode='transparent' bgcolor='transparent' sifr='true' type='application/x-shockwave-flash' class='sIFR-flash1' style='width: 282px; height: 20px;'/><span class='sIFR-alternate'>Document Description</span></h2>" + d.DocDescription + "<BR><p>Please fill out the following information so that we can proceed with providing you the link to the document</p><form  id='myDocForm' name='myDocForm' action='" + d.DataSubmissionPath + "' method='POST' ><table class='clearBoth' width='45%'><tr><td><input type=hidden name='oid' value='" + d.OID + "'></td><td><input type=hidden name='retURL' value='" + "" + "'></td></tr><tr><td class='formlabel' >First Name*</td><td class='formfield'><input type='text' id='first_name' size='20' maxlength='40' name='first_name'></td></tr><tr><td class='formlabel'>Last Name*</td><td class='formfield'><input type='text' id='last_name' size='20' maxlength='40' name='last_name'></td></tr><tr><td class='formlabel'>Email*</td><td class='formfield'><input type='text' id='email' size='20' maxlength='40' name='email'></td></tr><tr><td class='formlabel'>Work Title</td><td class='formfield'><input type='text' id='work_title' size='20' maxlength='40' name='work_title'></td></tr><tr><td class='formlabel'>Company</td><td class='formfield'><input type='text' id='company' size='20' maxlength='40' name='company'></td></tr><tr><td class='formbuttons'><input type='Button' name='btnsubmit' value='Submit' onclick='showDocPanel();'></td></tr></table></form>"

【问题讨论】:

  • 能否提供文字控件的内容?
  • 查看源码时,看到&lt;form&gt;元素了吗?并不是说您有两种形式(一种来自 asp.net),因此它们的行为不会像您期望的那样。你试过老式的 iframe 吗?
  • 抱歉 stackoverflow.com 没有在我结束时打开,所以我无法早点回复您的帖子。 @Kobi:当我查看页面的源代码时,我看不到表单,我知道我有两种表单,一种是 aspnet,一种是基于普通 html 的......但问题是我已经让它在其他方面工作了浏览器,但不是 IE
  • @Himadri:我已经添加了文字控制内容
  • Kobi 能否也请您向我解释一下 iframe 方法...因为我不确定我在互联网上找到的 iframe 方法是否适用于我的情况.. thnx

标签: asp.net html internet-explorer


【解决方案1】:
【解决方案2】:

我必须采取以下解决方法:

我使用 Request.Browser.Browser 检查浏览器是否为 IE...,然后我将文字文本修改为以下内容:

 Dim s As New StringBuilder
    s.Append("<iframe name='myIframe' style='visibility:hidden;height:0;width:0;'></iframe><div style='clear:both'></div><h2 class='sIFR-replaced1' style='text-align:left'><embed height='20'  id='h2heading' width='282' src='swf/frutiger_light.swf' quality='best' flashvars='txt=Document Description&amp;textalign=left&amp;offsetTop=0&amp;textcolor=#878787&amp;hovercolor=#76b404&amp;linkcolor=#87be22&amp;w=282&amp;h=20' wmode='transparent' bgcolor='transparent' sifr='true' type='application/x-shockwave-flash' class='sIFR-flash1' style='width: 282px; height: 20px;'/><span class='sIFR-alternate'>Document Description</span></h2><p align='left'><i>" + d.DocDescription + "</i><BR><BR></p>")
    s.Append("<p>Please fill out the following information so that we can proceed with providing you the link to the document</p>")
    If (Not Request.Browser.Browser.Equals("IE")) Then
        s.Append("<form  id='myDocForm' name='myDocForm' target='myIframe' action='" + d.DataSubmissionPath + "' method='POST' >")
    End If

    s.Append("<table class='clearBoth' width='45%'><tr><td>")
    s.Append("<input type=hidden name='oid' id='oid' value='" + d.OID + "'></td><td>")
    s.Append("<input type=hidden name='retURL'  id='retURL' value='" + "" + "'></td></tr>")

    ' debug(info)
    s.Append("<input type='hidden' name='debug' value=1>")
    s.Append("<input type='hidden' name='debugEmail'")
    s.Append("value=''>")

    s.Append("<tr><td class='formlabel'>First Name*</td>")
    s.Append("<td class='formfield'><input type='text' id='first_name' size='20' maxlength='40' name='first_name'>")
    s.Append("</td></tr>")
    s.Append("<tr><td class='formlabel'>Last Name*</td>")
    s.Append("<td class='formfield'><input type='text' id='last_name' size='20' maxlength='40' name='last_name'>")
    s.Append("</td></tr>")
    s.Append("<tr><td class='formlabel'>Email*</td>")
    s.Append("<td class='formfield'><input type='text' id='email' size='20' maxlength='40' name='email'>")
    s.Append("</td></tr>")
    s.Append("<tr><td class='formlabel'>Work Title</td>")
    s.Append("<td class='formfield'><input type='text' id='work_title' size='20' maxlength='40' name='work_title'>")
    s.Append("</td></tr>")
    s.Append("<tr><td class='formlabel'>Company</td>")
    s.Append("<td class='formfield'><input type='text' id='company' size='20' maxlength='40' name='company'>")
    s.Append("</td></tr>")
    s.Append("<tr><td>&nbsp;</td>&nbsp;<td></td></tr>")     'empty row for spacer cells
    s.Append("<tr><td>&nbsp;</td><td class='formbuttons'  align='right'><input type='Button' id='btnsubmit' name='btnsubmit' value='Submit' onclick='showDocPanel();'>")
    s.Append("</td></tr>")
    s.Append("</table>")
    If (Not Request.Browser.Browser.Equals("IE")) Then
        s.Append("</form>")
    End If
formSalesForce.Text=s.ToString()

所以 IE 浏览器显示表格,因为在使用 IE 时没有附加到文字的标签。

现在;在使用 IE 时,我担心将表单发布到外部网站,因为没有表单,无法提交......因此我不得不使用由 javascript 创建的重复表单:

使用了取自该网站的这段 javascript 片段:http://en.allexperts.com/q/Javascript-1520/create-form-submit-fly.htm

 function getNewSubmitForm(){
 var submitForm = document.createElement("FORM");
 document.body.appendChild(submitForm);
 submitForm.method = "POST";
 return submitForm;
}

//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
 var newElement = document.createElement("<input name='"+elementName+"' id='" + elementName + "' type='hidden'>");
 inputForm.appendChild(newElement);
 newElement.value = elementValue;
 return newElement;
}

//function that creates the form, adds some elements
//and then submits it
function createFormAndSubmit(){
var submitForm = getNewSubmitForm();
//alert("form created");
createNewFormElement(submitForm, "oid", document.getElementById("oid").value);
createNewFormElement(submitForm, "debug", "1");
createNewFormElement(submitForm, "debugEmail", "");
createNewFormElement(submitForm, "first_name", document.getElementById("first_name").value);
createNewFormElement(submitForm, "last_name", document.getElementById("last_name").value);
createNewFormElement(submitForm, "email", document.getElementById("email").value);
createNewFormElement(submitForm, "work_title", document.getElementById("work_title").value);
createNewFormElement(submitForm, "company", document.getElementById("company").value);
createNewFormElement(submitForm, "retURL", window.location.href);
//alert(window.location.href + "::elements added");
submitForm.action= "my external website url";
submitForm.target='myIframe';
//alert("submitting");
submitForm.submit();
}

现在当表单提交到外部 url 时会发生回发,以解决我所做的:

  • 创建了一个隐藏的 iframe 并将其附加到文字文本(有关文字文本,请参见上面的代码)
  • 将表单目标设置为该框架的名称(有关文字文本,请参见上面的代码)
  • 将复制的 javascript 表单的目标设置为该框架的名称(参见上面的 javascript 代码)

【讨论】:

    【解决方案3】:

    将表单边距设置为零也应该有效:

    .formStyle { 边距:0px; }

    【讨论】:

      猜你喜欢
      • 2021-05-18
      • 1970-01-01
      • 2018-10-19
      • 2011-12-27
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多