How t开发者_Go百科o open the homepage in FULLSCREEN with JavaScript without opening a new window?
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).
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.
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.
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.
Write a function in javascript
document.getElementById('<%=btnSubmit.ClientID%>').onclick(function(){
window.location = "http://myweb.com/home";
return false;
});
精彩评论