Javascript Not Working in Firefox

Last post 11-02-2009, 7:49 PM by Kenneth. 3 replies.
Sort Posts: Previous Next
  •  10-31-2009, 5:38 PM 56833

    Javascript Not Working in Firefox

    I built my own CuteEditor hyperlink insertion feature (for various reasons).  Here is what happens...
     
    1.  You click on an ASP/VB.Net ImageButton that opens an AJAX modal popup.
    2.  You input the hyperlink's display text and URL into the modal popup then click an ASP/VB.Net button.
    3.  A Javascript is invoked that formats markup for a hyperlink and inserts it into the CuteEditor window.
     
    This all works perfectly fine in IE.  In Firefox however, you go through all these steps...but no hyperlink appears.  The editor window seems to flash like it does in IE when the hyperlink actually appears...but no hyperlink appears in Firefox.  In Safari (on a Mac)...it's worse...not only does the hyperlink fail to appear...but any text that was already in the editor window disappears.  I will show the code that I use to do all this in hope that perhaps somebody knows what is happening differently between the way IE handles the Javascript and the way Firefox and (especially) Safari handles the Javascript...
     
    First, here is an ASP/VB.Net button that I use to open a modal popup that gets the display text and URL for the hyperlink:

    <
    asp:ImageButton ID="imb_InsertHyperlink" Visible="true" ImageUrl="~/CuteSoft_Client/CuteEditor/Images/link.gif" runat="server" />
     
    This is the button in the modal popup that I use to call the Javascript:

    <
    asp:Button ID="btnInsertHyperlink" Text="Insert" style="width: 115px; " runat="server" OnclientClick="InsertHyperlink(this)" />
     
    Finally, here is the Javascript that I use to insert the hyperlink into the text editor portion of CuteEditor:

    function InsertHyperlink()

    {

    var editor1 = document.getElementById('<% = Editor1.ClientID%>');

     

    var DisplayText = document.getElementById('ctl00$ContentPlaceHolder_Outer$txtInsertHyperlinkDisplayText').value;

    var DisplayURL = document.getElementById('ctl00$ContentPlaceHolder_Outer$txtInsertHyperlinkURL').value;

    var HyperLinkMarkUp = '<a href=\"' + DisplayURL + '\" target="_blank">' + DisplayText + '</a>';

    editor1.ExecCommand('PasteHTML',false,HyperLinkMarkUp);

     

    }

     
  •  11-02-2009, 4:05 AM 56838 in reply to 56833

    Re: Javascript Not Working in Firefox

    Hi MDCragg,
     
    Try this way
     
    Do not use server button to add the text, use input, like below.
    1. <%@ Page Language="C#" %>   
    2.   
    3. <%@ Register Namespace="CuteEditor" Assembly="CuteEditor" TagPrefix="CE" %>   
    4. <%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" TagPrefix="AJAX" %>   
    5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    6.   
    7. <script runat="server">   
    8.       
    9.     protected void btnClose_Click(object sender, EventArgs e)   
    10.     {   
    11.         ModalPopupExtender1.Hide();   
    12.     }   
    13. </script>   
    14.   
    15. <html xmlns="http://www.w3.org/1999/xhtml">   
    16. <head runat="server">   
    17.     <title>example</title>   
    18. </head>   
    19. <body>   
    20.     <form id="form1" runat="server">   
    21.     <asp:ScriptManager ID="ScriptManager1" runat="server">   
    22.     </asp:ScriptManager>   
    23.     <asp:UpdatePanel ID="UpdatePanel1" runat="server">   
    24.         <ContentTemplate>   
    25.             <asp:Button ID="btnShow" Text="Show" runat="server" />   
    26.             <AJAX:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="panel1"  
    27.                 TargetControlID="btnShow">   
    28.             </AJAX:ModalPopupExtender>   
    29.             <CE:Editor ID="editor1" runat="server">   
    30.             </CE:Editor>   
    31.             <asp:Panel ID="panel1" runat="server" BackColor="Black" Height="200px" Width="400px">   
    32.                 <asp:TextBox ID="textBox1" runat="server"></asp:TextBox>   
    33.                 <input type="button" onclick="addATag()" value="Add" />   
    34.                 <asp:Button ID="btnClose" runat="server" Text="Close" OnClick="btnClose_Click" />   
    35.             </asp:Panel>   
    36.         </ContentTemplate>   
    37.     </asp:UpdatePanel>   
    38.     </form>   
    39. </body>   
    40. </html>   
    41.   
    42. <script type="text/javascript">   
    43.   
    44. function addATag()   
    45. {   
    46. var editor1=document.getElementById('<%= editor1.ClientID %>');   
    47.   
    48.     
    49.   
    50. var DisplayText = document.getElementById('<%= textBox1.ClientID %>').value;   
    51.   
    52.   
    53. var HyperLinkMarkUp = '<a href="#" target="_blank">' + DisplayText + '</a>';   
    54.   
    55. editor1.ExecCommand('PasteHTML',false,HyperLinkMarkUp);   
    56.   
    57. }   
    58. </script>  
     
    Regards,
     
    Ken
  •  11-02-2009, 7:30 PM 56853 in reply to 56838

    Re: Javascript Not Working in Firefox

    I tried the Input button like you suggested.  It too works in IE but not in Firefox.  I wonder why Firefox and Safari won't respond to the Javascript.  :-\
  •  11-02-2009, 7:49 PM 56854 in reply to 56853

    Re: Javascript Not Working in Firefox

    Hi MDCragg,
     
    Is your site online? If so, please set up FTP for me and send me the test url.
     
     
    Regards,
     
    ken
View as RSS news feed in XML