Home >Web Front-end >JS Tutorial >Why Does My JavaScript Code Load HTML in Firefox but Prompts for a Plugin in Chrome?

Why Does My JavaScript Code Load HTML in Firefox but Prompts for a Plugin in Chrome?

Susan Sarandon
Susan SarandonOriginal
2024-11-29 18:56:14343browse

Why Does My JavaScript Code Load HTML in Firefox but Prompts for a Plugin in Chrome?

Loading an HTML Page into a Div Using JavaScript in Google Chrome

Question:

I'm attempting to load the "home.html" page into a div with the id "content" using JavaScript. The code works in Firefox, but it prompts for a plug-in in Google Chrome.

Code:

<script>
  function load_home() {
    document.getElementById("content").innerHTML = '<object type="type/html" data="home.html"></object>'
  }
</script>

Solution:

To resolve the issue in Google Chrome, modify the "type" attribute within the "object" tag as follows:

function load_home() {
  document.getElementById("content").innerHTML = '<object type="text/html" data="home.html"></object>'
}

By changing the "type" attribute to "text/html," the browser will now correctly load the HTML page into the specified div, eliminating the prompting for a plug-in.

The above is the detailed content of Why Does My JavaScript Code Load HTML in Firefox but Prompts for a Plugin in Chrome?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn