diff --git a/b0esche_cloud/lib/pages/document_viewer.dart b/b0esche_cloud/lib/pages/document_viewer.dart index 13f5291..8360b7a 100644 --- a/b0esche_cloud/lib/pages/document_viewer.dart +++ b/b0esche_cloud/lib/pages/document_viewer.dart @@ -459,8 +459,8 @@ class _DocumentViewerModalState extends State { Widget _buildCollaboraIframe(String collaboraUrl) { // For Collabora Online, we need to POST the WOPISrc, not GET it - // Create an iframe and submit a form to load the document - const String viewType = 'collabora-form'; + // Use JavaScript to create and submit the form properly + final String viewType = 'collabora-form-${DateTime.now().millisecondsSinceEpoch}'; ui.platformViewRegistry.registerViewFactory(viewType, (int viewId) { // Extract the WOPISrc from the URL @@ -477,7 +477,7 @@ class _DocumentViewerModalState extends State { // Create the iframe first final iframe = html.IFrameElement() - ..name = 'collabora-iframe' + ..name = 'collabora-iframe-$viewId' ..style.border = 'none' ..style.width = '100%' ..style.height = '100%' @@ -494,26 +494,36 @@ class _DocumentViewerModalState extends State { container.append(iframe); - // Create a hidden form that will POST to Collabora - final form = html.FormElement() - ..method = 'POST' - ..action = 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html' - ..target = 'collabora-iframe' - ..style.display = 'none'; + // Use JavaScript to create and submit the form + // This is more reliable than Dart's form.submit() + final jsCode = ''' +(function() { + var form = document.createElement('form'); + form.method = 'POST'; + form.action = 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html'; + form.target = 'collabora-iframe-$viewId'; + form.style.display = 'none'; + + var input = document.createElement('input'); + input.type = 'hidden'; + input.name = 'WOPISrc'; + input.value = '$wopisrc'; + + form.appendChild(input); + document.body.appendChild(form); + + // Submit the form + setTimeout(function() { + form.submit(); + }, 50); +})(); + '''; - // Add WOPISrc as a hidden input - final wopisrcInput = html.InputElement() - ..type = 'hidden' - ..name = 'WOPISrc' - ..value = wopisrc; - - form.append(wopisrcInput); - container.append(form); - - // Use a timer to submit the form after the iframe is fully loaded - Future.delayed(const Duration(milliseconds: 100), () { - form.submit(); - }); + final script = html.ScriptElement() + ..type = 'text/javascript' + ..text = jsCode; + + html.document.body!.append(script); return container; });