"The communication between systems failed" - specifically for Internet Explorer

I am attempting to create a new window using JavaScript and populate it with the HTML content from the current window. This is similar to a print preview in a new window, but with a different CSS style.

function openPrintPreview() {
        var printWindow = window.open("", "", "width=1020,height=750");
        printWindow.document.open();
        printWindow.document.write('<html><head><title>Test</title>');
        printWindow.document.write('<link href=print.css rel=Stylesheet></head><body>');
        printWindow.document.write(document.body.innerHTML);
        printWindow.document.write('</body></html>');
        printWindow.document.close();
        printWindow.focus();
}  

The function above is being called from this location:

<a id="print" href="#" runat="server" onclick="javascript:openPrintPreview();">PRINT</a>  

When testing in Internet Explorer, I encounter an error message "the remote procedure call failed" that appears to be related to this line:
printWindow.document.close();

In Firefox, everything works as expected. Any suggestions on troubleshooting this issue?

EDIT
My server environment is Windows Server 2008 R2 Standard SP1

EDIT2
Removing printWindow.document.close(); resolves the issue in Internet Explorer, displaying done in the status bar. However, this change causes Firefox to continuously load without completion. It seems like Firefox is waiting for the printWindow.document.close(); command to execute.

Answer №1

To harness the power of the DOM, it is advised to avoid using document.write as it is often considered as malicious practice.

For a better alternative, refer to the guidelines provided here:

Answer №2

While it may not be the most visually appealing solution, it appears to be effective.
I made a change to this section of code:

pr.document.close();  

I swapped it out with the following line:

if (navigator.appName != "Microsoft Internet Explorer") pr.document.close();

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

When I resize the screen size, my multiple item carousel in Bootstrap is failing to adjust and collapses

Whenever I try to resize the output screen, the carousel collapses and the last few items disappear. I really need the carousel to stay intact even when resizing. Can someone please assist me with this issue? Link to my CodePen ResCarouselSize(); $(w ...

What exactly does ".default" signify in Angular, Typescript, or Javascript?

Could someone please clarify the significance of the ".default" in the code snippet below? I am interested in implementing this code in our project, but my understanding of the mentioned code fragment is uncertain. (I have modified my question to display ...

Created a notification for when the user clicks the back button, but now looking to remove it upon form submission

My survey is lengthy and I don't want users to accidentally lose their data by clicking the back button. Currently, I have an alert that warns them about potential data loss, but the alert also pops up when they submit the form. Is there a way to disa ...

In JavaScript, the clearTimeout function may not always return a

Could someone please help me troubleshoot the issue in my code snippet below? I am trying to declare a public variable and assign it to a setTimeout function. If the variable is not null, I want to clear the timeout before setting it again. However, when ...

Terminate multiple axios requests using a common CancelToken

Within a single view, I have multiple react modules making API calls using axios. If the user navigates to another view, all ongoing API calls should be canceled. However, once they return to this view, these calls need to be initiated again (which are tri ...

Creating a seamless login experience using Hapi.js and AngularJS

It appears that I may need some clarification, here are the Docs for hapi I have this set up on the backend with hapijs and node.js. server.route({ method: 'POST', path: '/login', handler: function(request, reply) { USER: re ...

Should I keep my Mobx stores in a dedicated file or include them directly in the React component?

There are a couple of ways to define observable properties and actions in MobX. One way is to include them directly in the component like this: // App.js class App extends Component { @observable a = 'something' @action change() { this. ...

Incorporating multiple colors into a div with jQuery: A guide

I am looking for a way to create a legend by merging a specified number of colors within a div. I came across this useful Sample code that I have referenced. $.each(Array(50), function() { $("<div>").appendTo(document.body); }); var divs = $(&a ...

Modify the button's text with jQuery after it has been clicked

I've been struggling to update the text of a button after it's clicked, and I'm encountering an issue where it works in one part of my code but not in another. Could someone please guide me on what might be missing in my code? The first bl ...

Is there a way to remove data from both a JSON file and an HTML document?

Currently, I am facing a challenge with my code. I am unsure how to implement the functionality to delete a row when clicking on the X button and retrieve the unique ID of that particular row to append it to the URL. Unfortunately, finding the correct meth ...

Transfer a variable from one PHP page to another and navigate between the two pages

I am just starting to learn PHP and I have a scenario where I need to retrieve the last ID from the database. For each ID, I need to fetch the state and the associated link. If the state is equal to 1, then I need to extract some content from the link (whi ...

`Only firing event listener once`

I have created a JS module where I am adding a click event to all links that match a specific selector. Here is an example of how it's done: var Lightbox = (function () { var showLightbox = function () { // this does stuff }; var init = fu ...

Is the $scope object shared among all controllers in AngularJS when nested controllers are used?

Is it possible to use nested controllers in AngularJS? When using nested controllers, is the $scope object shared across all controllers? The issue at hand is:- While I can access the $scope values of the first controller across all controllers, I am una ...

Setting the initial state with an undo action in React: a step-by-step guide

Is it possible to display a snackbar with an undo action when dragging and dropping events in a react-big-calendar? https://i.stack.imgur.com/QFmYA.png I am trying to implement functionality where clicking on the undo action will revert the event back to ...

I pressed the button but the globalCompositeOperation isn't working as expected. How can I make it function correctly to achieve the desired output like the second canvas?

<!DOCTYPE html> <html> <head> <title>Canvas Compositing Tutorial</title> </head> <body> <canvas id="myCanvas" width="200" height="200" style="border: 1px solid"></canvas> <br> <butt ...

Open a web browser and continuously monitor the updates by using the `tail

Currently, I have developed a Python script that continually monitors a logfile for modifications (similar to the tail -f command) and showcases it on a console. I am interested in accessing the Python script's output through a web browser. What tools ...

Guide to Aligning Divs at the Center in Bootstrap 4

I've been attempting to center the div on the page using Bootstrap 4, however, it's not cooperating. I've tried using the margin:0 auto; float:none property as well as the d-block mx-auto class, but neither are working. Below is my HTML code ...

Tips for managing and capturing errors in Express

const database = require('database'); const express = require('express'); const app = express(); const cors = require('cors'); app.use(cors()); const bodyParser = require('body-parser'); const urlencodedParser = body ...

Struggling to remove the image tag from the jQuery ajax response

My web app is designed to send an ajax post request to a PHP script, which then returns a chunk of HTML data. This HTML includes an image and a table of information. The challenge I'm facing is how to extract the image from the rest of the HTML so tha ...

Using JavaScript with namespaces in C#

I am currently trying to explore AJAX and web services through self-teaching using C# and JavaScript. After doing some research on Google, it seems like I might be facing a namespace problem. Here is the snippet of my code: using System; using System.Col ...