Execute document.write and open within the current window

I'm encountering an issue while trying to write to a document:

NewWindow.document.write("Hi, this is test");
NewWindow = window.open("pages/Example.html","_self");

However, the page appears blank. If I use

NewWindow.document.write("Hi, this is test");
NewWindow = window.open("pages/Example.html","displayWindow");

It works but my intention is to rewrite the content of the current page.

var NewWindow = window.open("pages/Example.html","_self");
NewWindow.document.write("Hi, this is test");

I am aiming to create a window object, write to it, and then display it.

Answer №1

Just a little more tweaking and you'll have it, the key is the sequence in which you're performing those actions. Can you display content on a page that hasn't been loaded yet?

var NewWindow = window.open("pages/Example.html","_self");
NewWindow.document.write("Hello, this is just a test");

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

Ways to show the existing value of a <select> in a label without altering the function

I currently have a label that changes to display the selected option from a dynamic select dropdown, but it only updates when the selection is changed. I would like it to also display the current value when the page first loads. I attempted to change &apos ...

Acquiring the root URL with the $location service in AngularJS

I am facing a situation where I have a specific URL structure like the one shown below. http://localhost:8080/test#/users/list Upon further investigation, I discovered the following information: $location.url() returns -> "users/list" $location.path( ...

Exploring the execution of internal methods within an Angular service

My service is a simple one for Shoes app.factory('Shoes', function() { function x() {return 12;} function y() {return x();} return { x: x, y: y } }) I am trying to verify if the method x gets called when I invoke ...

Is it possible to use the POST method with NODE JS and JavaScript?

Struggling to set up a login screen, I keep running into a "cannot get post" error after hours of trying everything. Feeling defeated, I decided to seek help. Here's the code I have so far: const express = require('express'); const router = ...

When attempting to pass data to another page by clicking on a row, the result is that the data appears to be empty

I have been using the MUI-Datatable component, which is able to navigate to the next page. However, when I try to view the data on the History page, nothing appears. How can I resolve this issue? Data transfer to another page: Even though I can see the d ...

The linkType setting from MiniCssExtractPlugin and html-webpack-link-type-plugin both seem to be malfunctioning

I have provided my webpack configuration details below: const LinkTypePlugin = require('html-webpack-link-type-plugin').HtmlWebpackLinkTypePlugin; const path = require('path'); const webpack = require('webpack'); const FileMan ...

Observing a peculiar discrepancy in how various versions of JSON.stringify are implemented

Imagine having a deeply nested JS object like the example below that needs to be JSON-encoded: var foo = { "totA": -1, "totB": -1, "totC": "13,052.00", "totHours": 154, "groups": [ {"id": 1, "name": "Name A", " ...

What is the best way to create an array from a JSON object that specifically aligns with a particular key?

Currently, I am utilizing the API from themealdb.com which provides ingredient information in the following format: "strIngredient1": "Quinoa", "strIngredient2": "Butter", "strIngredient3": "Red Chilli ...

Implement concrete actions on the right-click context menu

I am exploring the functionality of this right-click context menu. Visually, it appears as expected, but I am unsure how to implement actual actions when the menu items are clicked. Currently, it only displays a message like "Back menu item was clicked - t ...

Copying to the clipboard now includes the parent of the targeted element

Edit - More Information: Here is a simplified version of the sandbox: https://codesandbox.io/s/stupefied-leftpad-k6eek Check out the demo here: https://i.sstatic.net/2XHu1.jpg The issue does not seem to occur in Firefox, but it does in Chrome and other ...

Link a function to a button in a 3rd party library

Whenever I click a button, there is a possibility of an alertify alert window appearing randomly. The alertify alert popup serves as a more aesthetically pleasing alternative to the traditional javascript Alert. Alertify library Below is a snapshot depic ...

"Failure encountered while trying to fetch JSON with an AJAX request

I am facing an issue with an ajax request. When I make the request with the property dataType: 'json', I get a parsererror in response. My PHP function returns the data using json_encode(), can someone assist me? On the other hand, when I make th ...

What is the best way to design a regular expression that will only match up to 12 numbers?

Is there a way to construct a regular expression that will validate a string containing up to 12 digits only? Thank you! ...

Navigating nested objects within an array: A guide to iterating through multiple layers of objects

After receiving a payload from Firebase, I found an array with 3 objects inside, each of which also contains additional objects. Here is the screenshot for reference: https://i.sstatic.net/kII6g.png When I console.log my 'months' array, this i ...

Is the OR (||) operator malfunctioning in the Angular.forEach method?

I am faced with the challenge of manipulating a JSON array by applying certain conditions for removal: var data = [ {data1: "aaa", data2: "bbb", data3: "ccc"}, // First {data1: "ddd", data2: "eee", data3: "fff"}, // Second ...

What is the best way to display HTML and JavaScript content using Express?

Currently, I am working on a simple express app which comprises of two routes. One route is responsible for rendering html, while the other route is supposed to render a JavaScript file. To keep things organized, I plan to store the html files in a ./views ...

Prevent ng-repeat from rendering the contents of my div

Currently, I am in the process of modifying a website for which I need AngularJS. I am trying to use the ng-repeat command to display some documentation on the site. However, whenever I add the ng-repeat within a div, it seems to "destroy" the layout and I ...

Encasing newly inserted child components within my designated slot

If I have a component with a single slot and instead of simply rendering all its children, I want to wrap each element individually, the following approach can be taken: Vue.component('MyElement', { render: function(createElement){ for (l ...

Having an issue in Angular 2 where the correct function is not triggered when a button is placed within a selectable anchor

Within an anchor element, I have a button that triggers its own click listener for an editing popup module. The anchor itself has another click listener assigned to it. For example: <a (click)="onClick(myId)" class="list-group-item clearfix"> < ...

The functionality of the web application is not supported in Multi-Device-Hybrid-Apps format

I am encountering an issue with my app that functions perfectly as a typical web app, but fails to work properly when converted into a Multi-Device-Hybrid-App format. The problematic sections are indicated in a screenshot of the app. Below is my complete c ...