Fixed: DocumentViewer will render a placeholder tag along with the script tag.We need a tag other than script tag for the component even if we render DOM on the client side.For example, Kendo UI Window, removes/moves script tags from content html so component is rendered to wrong placeand not inside the window.
Kendo UI Window has this code which caused the issue:// remove script blocks to prevent double-executionelement.find("script").filter(executableScript).remove();
@using GleamTech.AspNet.Core @using GleamTech.AspNet.UI @using GleamTech.DocumentUltimate.AspNet.UI <!DOCTYPE html> @{ Layout = null; var documentViewer = new DocumentViewer { Width = CssLength.Percentage(100), Height = CssLength.Percentage(100), }; } <html> <head> <meta charset="utf-8"/> <title>Kendo UI Snippet</title> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <script src="https://kendo.cdn.telerik.com/2024.2.514/js/kendo.all.min.js"></script> <link rel="stylesheet" href="https://kendo.cdn.telerik.com/themes/8.0.1/default/default-ocean-blue.css"> <script src="https://unpkg.com/jszip/dist/jszip.min.js"></script> @this.RenderHead(documentViewer) </head> <body> <div id="dialog"> @this.RenderBody(documentViewer) </div> <script> $("#dialog").kendoWindow({ width: "800px", height: "600px", title: "Document", modal: true, actions: [ "Pin", "Minimize", "Maximize", "Close" ] } ); </script> </body> </html>
Fixed: Error "TypeError: Failed to construct 'URL': Invalid URL" was thrown when DocumentViewer was rendered as contentinside Kendo UI Window. The reason is that when added as content in Kendo Window, weird stuff happens,document.currentScript refers to inline script tag which has jquery code and document.currentScript.src comes as empty stringthus the URL constructor error. Avoided using document.currentScript.src when it's empty in cases like this one,as the issue may also appear in other UI frameworks.
Improved: Added EscapeClosingScriptTags method to RazorPageExtensions, WebViewPageExtensions and WebPageExtensionswhich escapes closing script tags </script>, i.e. replaces with <\/script>.
When you render a component inside a tag, for example when you set a javascript variable tothe result of inline @RenderHead or @RenderBody calls, the result may contain closing tagsand browser treats these tags as an immediate stop even if they are enclosed in a javascript string literal:
<script> //this will fail in browser because there are closing `</script>` tags in the rendered result. var html = `@this.RenderBody(component)`; </script>
So to prevent the issue, escape closing script tags when you are inside tag, with this method:
<script> var html = `@this.RenderBody(component).EscapeClosingScriptTags()`; </script>
Details: The browser finds the piece in the string and thinks that it is the closing tagof the first script element. It treats the rest of the script and the real closing tag as regular textand displays it in the page (except for the tag).
@using GleamTech.AspNet.Core @using GleamTech.AspNet.UI @using GleamTech.DocumentUltimate.AspNet.UI <!DOCTYPE html> @{ Layout = null; var documentViewer = new DocumentViewer { Width = CssLength.Percentage(100), Height = CssLength.Percentage(100), }; } <html> <head> <meta charset="utf-8"/> <title>Kendo UI Snippet</title> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>; <script src="https://kendo.cdn.telerik.com/2024.2.514/js/kendo.all.min.js"></script>; <link rel="stylesheet" href="https://kendo.cdn.telerik.com/themes/8.0.1/default/default-ocean-blue.css">; <script src="https://unpkg.com/jszip/dist/jszip.min.js"></script>; </head> <body> <div id="dialog"></div> <script> $("#dialog").kendoWindow({ width: "800px", height: "600px", title: "Document", modal: true, actions: [ "Pin", "Minimize", "Maximize", "Close" ] } ); var dialog = $("#dialog").data("kendoWindow"); var html = ` @this.RenderHead(documentViewer).EscapeClosingScriptTags() @this.RenderBody(documentViewer).EscapeClosingScriptTags() `; dialog.content(html); </script> </body> </html>
Trouble logging in? Simply enter your email address OR username in order to reset your password.
For faster and more reliable delivery, add notify@gleamtech.com to your trusted senders list in your email software.