Legacy Knowledge Base
Published Jun. 30, 2025

Some pages are loaded blank when switching between pages when using the "document.write" javascript code

Written By

Jorge Diaz

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

We have upgraded from Liferay 6.2 to DXP 7.4.

We have problems with some pages, if you open a direct link to them, they are correctly loaded, but if you switch between pages, they are loaded blank.

We have detected the issue is only produced when the page contains a javascript code with a call to the document.write code in a web content or a page fragment or page configuration

Why this problem is produced? How can I solve it?

Environment

  • Any Liferay DXP 7.x version
  • Any Quarterly Release

Resolution

The document.write instruction does not cause problems when the page loads normally, but it does produce errors when the page is loaded with single-page application (SPA) functionality.

The reason why document.write causes problems with single-page application (SPA) is because:

  1. When changing pages, this functionality loads the HTML of the new page in the background and loads the contents by modifying the DOM structure of the page in memory, making it appear to the end user to have loaded much faster.
  2. The downside is that after loading, this functionality has to process all the Javascript code of the updated page and force the execution of those fragments.
  3. The problem is that at that point the document stream is already closed and using document.write when the stream is closed implies that document.open() is executed internally, which causes the document to be cleared.

You can find information about these problems caused by using document.write method in the following documentation: https://developer.mozilla.org/en-US/docs/Web/API/Document/write which explains that this method is strongly discouraged and the reason why the document is cleared.

In order to avoid the problem you are reporting, you have two options:

  • Option 1: Review the web content of your system and eliminate all uses of document.write
  • Option 2: Keep document.write and disable SPA functionality by adding the following to your portal-ext.properties: javascript.single.page.application.enabled=true (see Disabling SPA for more information)

We recommend opting for the first option.

Additional Information

In DXP 7.4 or Quarterly releases, if you want to detect which web contents you have with the document.write line to delete, you can use the following SQL:

SELECT * FROM JournalArticle WHERE (articleId, version) IN (SELECT articleId, MAX(version) AS version FROM JournalArticle WHERE id_ IN (SELECT DISTINCT storageId FROM DDMFieldAttribute WHERE largeAttributeValue LIKE '%document.write%') GROUP BY articleId);

 

 

Did this article resolve your issue ?

Legacy Knowledge Base