Ticket Q535892
Visible to All Users

Add an option to export a report to html with no javascript

created 11 years ago

If I have a report with images or labels which have a NavigateUrl set and I export that report to html, the navigation functionality is provided via the xr_NavigateUrl javascript function. If I then use this html as the body of an email, when the email is received in Outlook the links don't work as it won't allow the javascript to run. Could we please have a html export option which makes the resulting html have no javascript in it, and use normal anchors for the links instead?

I'm aware that this could be done by modifying the html after it is exported, and that's exactly what I'm about to attempt to do, but it would be nice if there was an export option that just avoids using any javascript.

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello Nathan,
Thank you for the detailed explanation of this issue.
I understand your point and informed our developers of this feature request. They'll take it into account when planning new features for our future release.
At the moment, to achieve this goal, I suggest you handle the HtmlItemCreated event for the necessary XRControl and modify its HTML content manually.
Feel free to contact us if you have further questions.
Thanks,
Dmitry

    Comments (1)
    Igor D (DevExpress) 11 years ago

      To clarify. The original question has been asked in the context of the Report Server. Unfortunately, the solution provided is not applicable for the Report Server because the report's code behind is not available.

      Other Answers

      created 11 years ago

      To clarify, I am already manually executing and exporting the report using an ExportAndGetFileDataTask similar to the one in E3422, so I already have access to the HTML string. I have also found a method of modifying the HTML as required, however my method may not work on all documents, and I think there's plenty of reasons why people would want to make javascriptless html, so I believe this should be a built-in export option.

      For reference, here is my function (VB.NET) that removes the javascript and replaces the onmousedown events with anchors. Just pass in the HTML string and it will modify it directly. I have made use of the HTML Agility Pack in order to process the HTML accurately.

      Private Sub RemoveJavascript(ByRef HTML As String) ' Load the HTML string into a document for easier parsing
              Dim Doc As New HtmlDocument
              Doc.LoadHtml(HTML)

      ' Remove the script tag
              Doc.DocumentNode.SelectSingleNode("//script").Remove()

      ' Add a style to remove underlines from anchors
              Dim Style As HtmlNode = Doc.DocumentNode.SelectSingleNode("//style")
              Style.InnerHtml = String.Format("{0}{1}{1}a {{text-decoration:none;}}{2}", ControlChars.CrLf, ControlChars.Tab, Style.InnerHtml)

      ' Loop through each td which has an onmousedown attribute
              For Each Node As HtmlNode In Doc.DocumentNode.SelectNodes("//td[@onmousedown]")
                  ' Extract the target url
                  Dim OnMouseDown As HtmlAttribute = Node.Attributes("onmousedown")
                  Dim NavigateMatch As Match = Regex.Match(OnMouseDown.Value, "'([^']*)'[^']*'([^']*)'")
                  Dim NavigateUrl As String = NavigateMatch.Groups(1).Value
                  Dim NavigateTarget As String = NavigateMatch.Groups(2).Value
                  Node.Attributes.Remove(OnMouseDown)

      ' Find the innermost node of the td which isn't a text node
                  Dim IsLastNode As Boolean = False
                  Do
                      Dim NextNode As HtmlNode = Node.ChildNodes.FirstOrDefault(Function(n) n.NodeType <> HtmlNodeType.Text)
                      If NextNode Is Nothing Then
                          IsLastNode = True
                      Else
                          Node = NextNode
                      End If
                  Loop Until IsLastNode

      ' Add the anchor node around the innermost node
                  Dim Parent As HtmlNode = Node.ParentNode
                  Dim Anchor As HtmlNode = Doc.CreateElement("a")
                  Anchor.SetAttributeValue("href", NavigateUrl)
                  If Not String.IsNullOrWhiteSpace(NavigateTarget) Then
                      Anchor.SetAttributeValue("target", NavigateTarget)
                  End If
                  Anchor.AppendChild(Node)
                  Parent.ReplaceChild(Anchor, Node)
              Next

      HTML = Doc.DocumentNode.OuterHtml
          End Sub

        Comments (1)
        DevExpress Support Team 11 years ago

          Hi Nathan,
          Thank you for sharing your code. We greatly appreciate it. We will consider implementing this functionality in a future Report Server version.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.