skip to Main Content

On button click, I am opening a blank window and after small delay loading a word document.

However I want to show loading text at initial load until that new window/tab gets replaced with documents.

I am preferring

Window.write("<div>loading</div>");

Is there any better approach?
Is it safe to use write method?

As it’s new/blank window, I can’t use create elements ( head , body is not exist in new window)

Used window write() which work fine

2

Answers


  1. While there is no issue using window.write() it would be better to load an HTML document with your loading markup already in place, that then loads content via a script.

    Ideally you do not have to load anything via scripts and it can all be served as static HTML.

    If you’re loading a file for the user I would recommend linking directly to it as a download rather than implementing a loading page for it. You can read more here:

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download

    Login or Signup to reply.
  2. I don’t think that there is a write method on the window object. There is document.write() method, it may work in some browsers but it is deprecated as per MDN.

    I am interested to know how window.write() works for you.

    If you are still interested in knowing how to use document.write, attaching a snippet here.

    https://codepen.io/anup-gopi/pen/GgKXrgP

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search