1

How to open the homepage in FULLSCREEN with JavaScript without opening a new window?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
xRobot
  • 25,579
  • 69
  • 184
  • 304
  • Could you clarify? You want to set a current page's size to full screen? – Matt Ball Oct 07 '10 at 14:25
  • 15
    If you resize my browser, I will leave you site and never come back. – Paul Tomblin Oct 07 '10 at 14:26
  • 2
    Just keep in mind that resizing browser windows is considered bad practice usability wise: leave it up to the user to determine at what size they view their pages; don't choose for them. But maybe this answer is what you're looking for? http://stackoverflow.com/questions/1125084/how-to-make-in-javascript-full-screen-windows-stretching-all-over-the-screen. But as you can read, it'll also depend on the browser and user settings if you even _can_ change the size. – Alec Oct 07 '10 at 14:27
  • agreed with @Paul Tomblin -- I *loathe* sites that do this. – Spudley Oct 07 '10 at 14:36
  • Either the user wants to go full-screen with the current page, which they can do without your help on every browser I know of, or they don't, in which case I'm with Paul and Spudley -- don't do that. :-) There is a limited UX case for opening a *new* window full-screen, but you've specifically said you don't want that, so... – T.J. Crowder Oct 07 '10 at 14:56

5 Answers5

9

To start with, please don't do that. Changing the browser size without the user's consent is usually very annoying.

Some modern browsers don't allow JavaScript to resize the browser window (I'm assuming this is what you mean by full screen) if the window wasn't opened by a script. The only way to get around that is to change the browser's configuration. So, essentially, if the browser doesn't allow it, there's nothing you can do. You'll have to open a new popup and resize it to fill the screen (and annoy some users).

Ates Goral
  • 137,716
  • 26
  • 137
  • 190
  • 2
    +1 for leaving my browser alone. Write the web application, do not mess with my client browser! – Chris Oct 07 '10 at 15:00
4

I assume you're doing this in direct response to the user clicking a button saying "go fullscreen" or similar. Mind you, every browser I know of already has that built in.

You could use the window.moveTo (MDC link, MSDN link) and window.resizeTo methods (MDC link, MSDN link). The browser may disallow it, although if it's in direct response to a user action, it may allow it. In any case, it's non-standard.

Frankly, though, it's off-topic but I think you're much better off opening a new window (being clear with the user what you're doing) in virtually all UX cases. Opening a full-screen window via window.open is straightforward and (if done in direct response to a user-generated event) well-supported.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

It is not possible to do this with JavaScript without using a new window (and this can vary from browser to browser).

Only external applications, such as Flash, can create full screen events.

graham
  • 946
  • 5
  • 16
0

you could try to set window.innerHeight/window.innerWidth and the window position with javascript to create a faked "fullscreen-look-a-like"-effect. but note that this wouldn't work cross-browser/cross-os.

but: why the hell do you want to do this? if it's a "normal" webpage the only effect you'll get is banish and annoy your visitors. if it's a intranet-application with only some users that know what happens, it would be easier to tell them they should better press F11.

oezi
  • 51,017
  • 10
  • 98
  • 115
-3

Write a function in javascript

document.getElementById('<%=btnSubmit.ClientID%>').onclick(function(){
 window.location = "http://myweb.com/home";
return false;
});
ImadArif
  • 89
  • 6
  • `getElementByID` should be `getElementById`, there was no mention of (what I assume to be) ASP.NET anywhere in the question, DOM elements don't have a click method, and setting window.location won't cause the browser to resize the window. – Quentin Oct 07 '10 at 15:02