Hidden window using javascript
Asked Answered
K

3

15

Just wanted to know if it is possible to create a hidden window using javascript?

Kane answered 3/3, 2011 at 12:27 Comment(1)
Regarding the question, what's your goal? If you want to send data to the server without user seeing something, simply use AJAX.Poseidon
C
14

You can create an iframe

var element = document.createElement("iframe"); 
element.setAttribute('id', 'myframe');
document.body.appendChild(element);

You can hide an iframe by setting its width and height to zero or by setting its visibility to hidden in the stylesheet.

Cystotomy answered 3/3, 2011 at 12:29 Comment(2)
Actually element.style.display = "none"; is the ideal way to have it hidden as far as I know.Poseidon
I've read on someone's blog that iframe may not work properly if we set display to none, but it were not mentioned in what case exactly. Maybe you're right :)Cystotomy
U
11

You can also create a new window visible only in taskbar with this workaround:

window.open(path.html,'_blank', 'toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,left=10000, top=10000, width=10, height=10, visible=none', ''); 

that open a window in a position not visible by user. I have used this trick different times.

Urge answered 22/10, 2013 at 15:2 Comment(4)
I tried this in IE10, i dont know why it didnt worked for me....will give it another tryBurget
Try to play with position left and right. I used 10000 as random big number. How did you see the windows in IE10?Urge
Does not work on MacOSForeshadow
Does not work anymore, probably for good reasonsRachael
C
0

Under IE 9+ you can create a window off-screen:

var options = "left=" + (screen.width*2) + ",top=0";
var myWin = window.open(url, name, options);
// Hide the window - IE only
myWin.blur();
// Show the window - IE only
myWin.focus();

screen.width is your monitor width. Using "*2" allows for users with dual monitors.

This does not work under Chrome.

Chui answered 10/12, 2014 at 23:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.