iframe功能可在Firefox中运行,但不能在IE中运行 [英] iframe function working in Firefox but not working in IE

查看:87
本文介绍了iframe功能可在Firefox中运行,但不能在IE中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
在将值发送到数据库之前,我有一个页面将在gridview中存储临时数据.临时表gridview中的值将提供到google的链接,在其中搜索单词并在iframe中显示结果.
在Firefox中可以正常使用,但在Internet Explorer中不能使用.
有什么方法可以克服这些家伙吗?

这是我的aspx代码:

Hi.
I have a page where it will store temporary data in gridview,before we send the values to database.The values in temporary table gridview will give a link to google,where it will search the word and display results in iframe.
This works fine in firefox,but not working in internet explorer.
Is there any ways to overcome this guys?

Here''s my aspx code :

<body>
    <div>
    <table>

    <tr>
    <td class="style1">
    <asp:Label ID="Label1" runat="server" Text="Caller Info :"></asp:Label>
    </td>
    <td style="width: 100px">
    <asp:TextBox ID="TxtName" runat="server" class="cls" onekeypress=""  autocomplete="off" ToolTip="Press Enter key for new input"></asp:TextBox>
    </td>
    </tr>
    <tr>
  <td class="style1">
      <asp:Label ID="Label2" runat="server" Text="Date :" Visible="False"></asp:Label>
  </td>
  <td style="width: 100px">
  <asp:TextBox ID="TextBox3" runat="server" ReadOnly="True" Visible="False"></asp:TextBox>

  </td>
  </tr>
  <tr>
  <td class="style1">
  <asp:Label ID="Label3" runat="server" Text="Time :" ></asp:Label>
  </td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
       <script type="text/javascript">
        function ShowTime() {
        var dt = new Date();
        document.getElementById("<%= TextBox2.ClientID %>").value = dt.toLocaleTimeString();
        window.setTimeout("ShowTime()", 1000);
    }
    </script>
</td>
  </tr>
  <tr>
  <td>
      <asp:Label ID="Label4" runat="server" Text="User :" Visible="False"></asp:Label>
  </td>
  <td style="width: 100px">
      <asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" Visible="False"></asp:TextBox>
  </td>
  </tr>
  <tr>
  <td>
      <asp:Label ID="Label5" runat="server" Text="IP :"></asp:Label>
  </td>
  <td style="width: 100px">
      <asp:TextBox ID="TextBox4" runat="server" ReadOnly="True"></asp:TextBox>
  </td>
  </tr>
    </table>

    <asp:Button ID="BtnAddToTable" runat="server" align="right" class="cls"

    Text="Add" OnClick="BtnAddToTable_Click" />

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
    <Columns>
    <asp:TemplateField HeaderText="Caller Information">
    <ItemTemplate>
    <a onclick='document.getElementById("<%=iframe1.ClientID%>").src = this.href; return false;' href='http://www.google.com/#q=<%#DataBinder.Eval(Container.DataItem,"name")%>'>
    <%#DataBinder.Eval(Container.DataItem, "name")%></a>//----------->this is the code will search in google in iframe.working fine in firefox but not in ie.
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="">
    <ItemTemplate>
    <asp:Button ID="BtnDelete" runat="server" Text="Clear" OnClick="BtnDelete_Click" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    <iframe runat="server" id="iframe1" src="" class="cls"

     style="z-index: 105; left: 225px; position: absolute; top: 109px; width: 875px; height: 455px;" frameborder="1" title="Google Search Display" ></iframe>

</div>
        <asp:Button ID="BtnSendToDatabase" runat="server" class="cls" Text="Save to database" OnClick="BtnSendToDatabase_Click" OnClientClick="return AddConfirmation()" />
</body>

推荐答案

在此行上引起的问题... href =''http://www''

尝试这种方式..

problem causing on this line... href=''http://www''

try this way..

<script language="javascript">
    function calllink(a)
    {
        alert(a);
        document.getElementById('iframe1').src = a;
        alert(a);
    }
</script>
<body>
    <div>
       <a onclick='calllink("http://www.google.com/")' href="#">hello</a>
    <iframe runat="server" id="iframe1" class="cls" style="z-index: 105; left: 225px; position: absolute; top: 109px; width: 875px; height: 455px;" frameborder="1" title="Google Search Display" ></iframe>
</div>
</body>



onclick事件处理程序需要禁止链接的默认行为,以导航href属性中指定的行为.您应该这样使用:

onclick event handler needs to supress the links default behavior to navigate that specified in the href attribute. you should use like this:
<a href="#" onClick="myFunc(); return false"><img src="image.jpg"></a>


使用span标签的另一种方法


an another way by using span tag

<span style="cursor: hand; display: block;" onclick="alert('You clicked me');">Click </span>



您是否尝试过我以前发布的内容.所有浏览器的行为方式都不同...



Did you tried what i posted before. All browsers acts in different way...


onclick事件处理程序需要禁止链接的默认行为,以导航href属性中指定的行为.您应该这样使用:

onclick event handler needs to supress the links default behavior to navigate that specified in the href attribute. you should use like this:

<a href="none" onClick="myFunc(); return false"><img src="image.jpg"></a>




如果这对您有帮助,请投票.




If this helps you then please vote.


这篇关于iframe功能可在Firefox中运行,但不能在IE中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆