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

Forums / Bugs & Issues / JavaScript Error In Page Edit Mode

JavaScript Error In Page Edit Mode

6 posts, 0 answered
  1. Shelley
    Shelley avatar
    4 posts
    Registered:
    24 Feb 2009
    15 Jul 2009
    Link to this post
    When I am in classic page edit mode (not content edit mode) and I click on a hyperlink, a blank window comes up with javascript:void(0) in the address bar. Is there a way to supress the click event for hyperlinks in edit mode and/or turn off javascript errors in edit mode?
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    17 Jul 2009
    Link to this post
    Hello Shelley,

    This behavior is actually by design. We do not want any javascripts to be executed in design mode, and explicitly set the links to not execute scripts (void).
    Actually I am not how this is causing an error. It is a standard way to disable the links. Can you please show us a screenshot?

    Thank you in advance.

    All the best,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Shelley
    Shelley avatar
    4 posts
    Registered:
    24 Feb 2009
    17 Jul 2009
    Link to this post
    Hi Georgi,

    Thank you for your response. I was wrong in using the word "Error" as it is not an error but an empty popup. Are there any possible workarounds for this issue?


    Thanks,
    Shelley
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    22 Jul 2009
    Link to this post
    Hi Shelley,

    I was thinking for different solutions, although that you should not get the described behavior on a regular links.
    Here is something you might try, I am not sure if it will work for you:

    1. Create a new class in the App_Code directory, named EditPageTweak:

    EditPageTweak.cs:
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Cms.Web; 
    using System.IO; 
    using System.Web.UI; 
     
    /// <summary> 
    /// Changes the javascript void(0) to return false; for page in Edit mode,  
    /// and links different than Sitefinity ones 
    /// /// </summary> 
    namespace Telerik.Sitefinity.Samples 
        public class EditPageTweak : EditPage 
        { 
            public EditPageTweak() 
            { 
                // 
                // TODO: Add constructor logic here 
                // 
            } 
            protected override void OnInit(EventArgs e) 
            { 
     
                string script = @"
                var cmscancelsubmit = true;
                SubmitHandler = function(e) {
                    if (!e)
                        var e = event;
                    if (e.preventDefault && cmscancelsubmit)
                        e.preventDefault();
                    return cmscancelsubmit == false;
                };
                function RemoveNavigation1(){
                    var els = document.getElementsByTagName(""a"");
                    for (i = 0; i < els.length; i++){
                        var el = els[i];
                        if (typeof(el.attributes[""allowDesignTime""]) == ""undefined""){
                            if (el.className != ""edit"" && el.className != ""delete""
                                && el.className != ""CmsButLeft ok"" && el.className != ""CmsButLeft light""
                                && el.className != ""cmscclcmd"" && el.className != ""cmstoolbox"" && el.className != ""uplCtrl""
                                && el.className != ""nextHelpStep"")
                                   {
                                     el.href = ""javascript:return false;"";
                                     el.target = ""_self"";
                                   }
                        }
                    }
                    var form = document.getElementById(""aspnetForm"");
                    if (document.all && form.attachEvent){  
                        form.attachEvent (""onsubmit"", SubmitHandler);
                    } 
                    else if (document.addEventListener){
                        form.style.cursor = """";
                        form.addEventListener(""submit"", SubmitHandler, false);
                    }
                }
       
                RemoveNavigation1();
                "
     
                base.OnInit(e); 
                this.ClientScript.RegisterStartupScript(this.GetType(), "CancelNavigate1", script, true); 
            } 
        } 

    2. Make the Edit pages inherit from this modification of EditPage class:
    Open the ~/Sitefinity/Admin/EditPage.aspx file and make it look like the following:
    <%@ Page Inherits="Telerik.Sitefinity.Samples.EditPageTweak" MasterPageFile="~/Sitefinity/Dummy.master" %> 

    This is the only solution I can suggest you to try.

    Let me know about the results.

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Connections Academy Developer
    Connections Academy Developer avatar
    151 posts
    Registered:
    04 May 2005
    05 Aug 2009
    Link to this post
    Thanks, after tweaking the code a bit it is working for me:

    el.disabled = true;

    instead of 

    el.href = ""javascript:return false;"";
    el.target = ""_self"";

    Thanks!
    Shelley

  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    06 Aug 2009
    Link to this post
    Hi,

    I am glad this worked. 
    Let us know if you have any other questions.

    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.
Register for webinar
6 posts, 0 answered