Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1015
Force relative path when inserting image
posted

When I insert an image the WebHtmlEditor puts the full path into the markup.  This is an issue because I am developing on my PC, it will then move to a development server for testing, and then it will move again to the production server - all of which have different base URLs but the same folder structure.  How do I tell the editor not to paste in the full path - only the relative path from the site root? 

I am using 7.1.20071.40 - would a newer version work better?

Here is my current code:

edExplanation.UploadedFilesDirectory = "~/UploadedFiles";

Parents
  • 1015
    posted

    Here is the code, partially given to me by Infragistics support, that creates a client side script for the AfterAction event.  Using this you can determine if the action was an image insert and adjust the rendered html accordingly to remove the base of the url from the string to make the image path relative.

    string afterActionEventScript = @"
    function edAfterAction(oEditor, actID, oEvent, p4, p5, p6, p7, p8){

    if (actID == 'InsertImage') {
    var txt = oEditor.getText();
    var homeURL = this.location.protocol + '//' + this.location.host + '"
    + Request.ApplicationPath + @"/';
    txt = txt.replace(homeURL, '');
    oEditor.setText(txt);
    }

    }";

    if (!Page.ClientScript.IsClientScriptBlockRegistered("edAfterAction"))

    {

    Page.ClientScript.RegisterClientScriptBlock(
    this.GetType(), "edAfterAction", afterActionEventScript, true);

    }

    edExplanation.ClientSideEvents.AfterAction = "edAfterAction";

     

    You can also handle other events, such as paste. NOTE: the "Paste" action only occurs when someone clicks the right-click menu or one of the standard menu buttons on the WebHtmlEditor - NOT on "ctrl-v". ie: (JavaScript, inside edAfterAction)

    if (actID == 'Paste') { alert('you just pasted something'); }

Reply Children