The document.write function causes the page to break

I have created a view that loads another view asynchronously and then replaces the current one using document.write (yes, I want to replace the whole page!):

$.ajax({
type: "GET",
url: myUrl,
data: null,
async: true,        
success: function (result) {

    document.close();
    document.open();
    document.write(result);
    document.close();
},
error: function (req, status, error) {
    $("#loading-div").html("error");
}
});

The content includes a full view with its own scripts and CSS styles. While everything works fine in IE or Chrome, loading the page in Firefox results in the loaded page via document.write not functioning properly - especially some of the scripts (some work, some don't).

I cannot use innerHTML because of scripts that are not evaluated.

Why is it not working properly only in Firefox (when even IE can handle it)?

Answer №1

In order to comply with the requirements, document.open is needed to establish a new global variable. Firefox fulfills this requirement, while Chrome does not; it's uncertain for IE.

If your script relies on the previous global variable remaining intact, it will function properly in Chrome but not in Firefox.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular Bootstrap Modal provides a sleek overlay for user input forms

Trying to access an angular form within scope for validation purposes. Initial Scenario Consider the following HTML: <body ng-controller='MyAwesomeController'> <form name="fooForm"> <textarea ng-model="reason" required= ...

Include a new button in the react material-table toolbar

I am looking to enhance the material-table toolbar by adding a new button. This button will not be directly related to the table, but instead, it will open a modal window with additional information. The button I want to add is called "quotations" and I w ...

Can media queries styles be applied to a window of random size using JavaScript?

Can JavaScript be used to apply media queries style based on random window sizes? I have 5 buttons that I want to switch styles for using JavaScript according to the media queries defined in my CSS stylesheet. Is there a method to achieve this? ...

javascriptif the number is a whole number and evenly divisible

I am currently developing a script that tracks the distance traveled by some dogs in meters. It is basically just a gif running in a loop. What I want to achieve now is to display an image every 50 meters for a duration of 3 seconds. Here's my attempt ...

Organizing month and year in angularjs: A step-by-step guide

I have a table with a column for month and year. I need to sort the dates by year. Can someone please help me with this? You can view the code in the provided fiddle. In my case, the date format is "MMMM yyyy". For example, if I have "August 2016", "Septe ...

Is it possible to request a GET on a server's JSON file using a specific key?

I am currently working on a project involving an auto-suggestion exercise using a JSON file located on a server. I'm not entirely clear on the web development terminology, so one requirement has me a bit confused: The requirement states: "On the keyu ...

What are alternative methods to secure the POST method without relying on SSL?

I'm currently working on a website where users submit their credentials using AJAX and PHP with the POST method. I am looking for ways to protect the login credentials without storing them in plain text, but without having to use an SSL certificate. I ...

Troubleshooting: jQuery AJAX not Invoking C# Method in ASP.NET MVC Application

I am attempting to initiate a call to the controller from the views using jQuery ajax, however, it seems like the controller is not being called. The goal is to pass the token value obtained on the registration page to the controller in order to utilize it ...

StorageLimit: A new condition implemented to avoid saving repetitive values in the localStorage

Is there a way to store the text of an li element as a localStorage value only once when clicked? If it already exists in localStorage, a second click should have no effect other than triggering an alert. I'm currently using an if statement inside a ...

Typeahead.js is a powerful tool offered by Twitter that allows for easy auto-completion

I am currently working on a program that has the capability to search for specific university courses based on certain parameters. Within my large JSON object, there are 1360 objects, each consisting of around 20-30 parameters. However, I am only intereste ...

Is it possible to utilize an API response within a conditional statement in NextJS?

I am working on a change password feature that interacts with an API for verification. If the current password entered is incorrect, I want to display an error message. If you have any suggestions on how to proceed or if there are any flaws in my approach ...

Merging Technology: Integrating Maps into Hybrid Applications

Currently, I am developing a mobile application using React-Native with a main focus on: Map Integration: Partial Success - I have successfully implemented all features mentioned in this link. The remaining task is to display live routing based on curren ...

Creating a dynamic pricing system for products in WooCommerce

Attempting to dynamically change the price of a WooCommerce product but unable to find a solution that works for my specific case. I have tried various methods suggested here without success. For example, I have an ajax function that triggers the receive_ ...

Prevent unauthorized AJAX requests from external sources within the Node application

I am looking for a way to prevent AJAX requests from being made outside of my application. I need to ensure that the response is not sent when the AJAX request is initiated from external sources, even if the URL is copied and pasted into a browser. My te ...

Each time the toggle is switched, an additional AJAX request is sent to the PHP document

I've been working on a function that sends data to a PHP file, which then processes the data. The PHP part works fine, but I'm having issues with the jQuery side of things. Each time I click on a ".work" element and trigger the toggle function, a ...

Updating a textbox with JQuery AJAX when the text in another textbox changes

Whenever I type something into an input field with the id "textbox1", I want to update another input field with the id "textbox2" accordingly. This is the code I started with: $("#textbox1").keyup(function(){ $.ajax({ type: "POST", ...

Add an element to the parent body from an iframe with this easy tutorial!

Within the iframe, I have the following code snippet. <script type="text/javascript"> $(document).ready(function(){ $("body").append($("#ctap").html()); }); </script> I am looking to append the HTML content of #ctap to the par ...

Determine the y-coordinate of terrain in Three.js

I have acquired a Collada model of terrain and now wish to incorporate other models onto this terrain. To achieve this, I believe I need to retrieve the height coordinate (y) of the terrain based on specific x and z coordinates. Can someone please guide ...

Using a for loop in JavaScript to dynamically generate HTML content within a Django project

Do you have a unique question to ask? Version: Django version 3.0.8 This block contains my JavaScript code: fetch(`/loadbox/${message.id}`) .then(response => response.json()) .then(dialog => { let detailcontent= `<div class=" ...

Creating and accessing a temporary binary file using Node Js

Challenge I have been working on integrating the Google Text To Speech (TTS) service to save a generated binary audio file to Google Cloud Storage (GCS). Considering that saving a local binary file in Firebase's Cloud Functions environment may not b ...