Questions tagged [window-object]

The Window object is a DOM interface that represents a browser window/tab that contains a DOM document. The Window object is defined in the HTML specification.

See also:

94 questions
0
votes
1 answer

Prompt Not working inside for loop in Javascript

alert("You will play 10 round and the highest scorer will win the game") //let player1 = prompt("choose") let element = ['snake', 'water', 'gun'] let player1_score=0 let player2_score=0 for (let i =0; i<10;i++) { let player1 =…
Shroud
  • 35
  • 7
0
votes
0 answers

How to import a type from a package and add it to the window object available for the whole project?

This is what I need to do: import type { Foo } from 'package-foo'; declare global { interface Window { foo: Foo; } } I would like it to be accessible from my entire src folder. How can I do this? Should I use a d.ts file? Triple slash…
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
0
votes
0 answers

window.location vs window.Location

What is the difference between window.location and window.Location in Javascript. The first one is object but the second one is a function, I know the use of the first one, but what is the use of second one?
Am1n
  • 13
  • 4
0
votes
2 answers

In Cypress component tests, changes to window object made inside component render cycle do not persevere

I need to expose some of my component's internals to Cypress component tests via window object, but I'm failing to pass and read it properly. Consider this code: // component import React, { FC } from 'react' (window as any).publicDictionary = {…
0
votes
1 answer

Asserting values of window object using jest

I am trying to assert the values of windows object using jest. For example: Asserting google tag manager's window.dataLayer values. How can I implement that using unit testing jest framework?
0
votes
1 answer

Define dynamic function in javascript

I am having SetUpTest() method, function name will be generated on-load of script by fetching window object. testShieldVal.js_name is variable, testShieldVal = window.testObject || {}; SetUpTest = testShieldVal.js_name+"SetUp"; function…
0
votes
0 answers

JS: How to get 'this' while being called by window event

The self pointer 'this' doesn't work when being called by window global event. class foo { bar(){ console.log("bar is called"); } event_handler(){ // At the time being called, 'this' here is 'window' //…
Dee
  • 7,455
  • 6
  • 36
  • 70
0
votes
1 answer

Window object properties behavior

When we have normal javascript objects, we can access there properties by using a syntax like objectName.proprtyName. If we just use propertyName only, then we will get an error as below - const myObj = { userIdName :…
Praneet Dixit
  • 1,393
  • 9
  • 25
0
votes
0 answers

How to retrieve data from `window` object - React?

I am super new to ReactJS. I am trying to assign third party script file to my Window obbject like below code in my componentDidmount method. const script = document.createElement("script"); script.src = "www.xxx.com/src/data.js"; …
0
votes
2 answers

Angular: event listener no longer triggered when I move mouse off component

I have a context menu in my Angular app, and I want to trigger a callback whenever a key is pressed while that context menu is open. I added the following code inside the constructor of my context menu: window.addEventListener('keydown', function()…
RNdev
  • 953
  • 1
  • 8
  • 26
0
votes
0 answers

What are the security risks of exposing the global object in browsers?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Securing_JavaScript See the section '"Securing" JavaScript' of that page. What does it mean by exposing the global object in browsers? Isn't the global object the window…
SRCP
  • 224
  • 2
  • 10
0
votes
1 answer

Online game bot performance

I'm creating bot for online dynamic game. In this case dynamic means that hero ingame can move around and background is changing when moving. Global variables like monsters are changing dynamic when moving as well. My bot is using puppeteer. Since I…
BT101
  • 3,666
  • 10
  • 41
  • 90
0
votes
1 answer

How to open a url in new window and then trigger ctrl + p (print)?

I have iframe within a div and have a print button, on clicking print I want to open a new tab and trigger print action for the url being shown in iframe. I am using Angular 7. Solutions I tried so far: How to open a link new tab with print…
Always_a_learner
  • 4,585
  • 13
  • 63
  • 112
0
votes
1 answer

javascript variable shows in console.log but not in browser output

I am trying to reuse the output of the year variable. I will need to reuse the updated value [based on hashchange] in multiple functions later on. It displays the correct value in the browser console, but it doesn't display in the…
Lid
  • 115
  • 11
0
votes
1 answer

Angular 2+ detect closing window

i have troubles detecting a closing window after the build is done. const newWindow = window.open(url, '_blank', options); newWindow.onbeforeunload = () => null; newWindow.addEventListener('beforeunload', (evt: BeforeUnloadEvent) => { …
sevic
  • 879
  • 11
  • 36