+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / JavaScript error when inserting an apostrophe in a hyperlink

JavaScript error when inserting an apostrophe in a hyperlink

6 posts, 0 answered
  1. Connections Academy Developer
    Connections Academy Developer avatar
    151 posts
    Registered:
    04 May 2005
    28 Jul 2009
    Link to this post
    When a user inserts a hyperlink using an onclick event that opens a rad window into a content module, if they insert an apostrophe ( ' ) into the text field, a js error is thrown:

    Error:" missing ) after argument list" 
    Source File: http://staging.www.connectionsacademy.com/_test/Hyperlink_Test.aspx?cmspagemode=preview&locknavigation=true 
    Line: 1, Column: 49 
    Source Code: 
    openRadWindow(this.href, 'My link My linkMy link's, My link',200,200,true); return false;


    Is there any way to check the text field for apostrophes and parse them so that this error does not occur?
  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    29 Jul 2009
    Link to this post
    Hello Connections Academy Developer,

    You need to escape the apostrophes in the string:
    openRadWindow(this.href, 'My link My linkMy link\'s, My link',200,200,true); return false;  
     

    You need to escape only the strings you have defined and escape the apostrophes.

    I hope this helps you.

    Sincerely yours,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  3. Connections Academy Developer
    Connections Academy Developer avatar
    151 posts
    Registered:
    04 May 2005
    10 Aug 2009
    Link to this post
    Hi Parvan,

    Is there any way to check the text field in codebehind so that the user does not have to type in the escape sequence?

    Thank You,
    Shelley 
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    13 Aug 2009
    Link to this post
    Hello,

    If you assign the link value to a variable first, then you could perform string escaping on this variable. Then after this procedure, you could assign the variable for the RadWindow parameter. 

    Perhaps we could help if you send us the user control that you are using. 

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  5. Connections Academy Developer
    Connections Academy Developer avatar
    151 posts
    Registered:
    04 May 2005
    13 Aug 2009
    Link to this post
    Here are the steps to recreate my problem:

    Edit a page in Sitefinity
    Insert a content module and edit it
    In HTML mode, add a link like the following: 

    <a href="#" onclick="openRadWindow(this.href, 'My Link's', 200, 200, true);">Popup Test</a>

    Here's the custom javascript function we are using:

    var myRadWindow;
    var errorPage404 = "/errors/404.aspx?popup=true";
    var errorPage500 = "/errors/500.aspx?popup=true";
    var errorPage = "/errors/error.aspx?popup=true";
    var errorPageHeight = 200;
    var errorPageWidth = 520;

    function openRadWindow(url, title, width, height, isModal) {
        // Use an XMLHttpRequest object to check the url for a 404 error
        // If there is a 404 error, display the error page within the radWindow
        $.ajax({
            url: url,
            success: function() { openRadWindowUrl(url, title, width, height, isModal); },
            error: function() {
                if (error = "404")
                    url = errorPage404;
                else if (error = "500")
                    url = errorPage500;
                else
                    url = errorPage;
                    
                openRadWindowUrl(url, title, errorPageWidth, errorPageHeight, isModal);
            }
        }); 

        return false;
    }

    function closeRadWindow(thisWindow) {
        top.myRadWindow.close();
    }

    function openRadWindowUrl(url, title, width, height, isModal) {
        myRadWindow = window.radopen(url, "masterPageRadWindow");

        myRadWindow.set_modal(isModal);
        // if the window is too big, resize it
        var winWidth = document.all ? document.documentElement.clientWidth : window.innerWidth;
        if (width > winWidth)
            width = winWidth - 20;

        var winHeight = document.all ? document.documentElement.clientHeight : window.innerHeight;
        if (height > winHeight)
            height = winHeight - 20;

        myRadWindow.set_width(width);
        myRadWindow.set_height(height);
        myRadWindow.center();
        myRadWindow.show();
    }

    Let me know if you need anything else.

    Thanks,
    Shelley

  6. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    18 Aug 2009
    Link to this post
    Hi Connections Academy Developer,

    You need to escape the string only if it is defined explicitly in the Java script code (like openRadWindow(this.href, 'My link My linkMy link\'s',...).

    If you get the string from a textbox for example there is no need to escape the string.

    Best wishes,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
Register for webinar
6 posts, 0 answered