Friday 2 March 2007

Opening a new browser window and maximising it..

I'm usually vehemently against this method of web development (never, ever break the back button!) but someone I know wanted to do this for their client, so I worked out a solution - I've pasted the code here so I can dole it out as and when needed... Obviously the usual disclaimer applies: don't do this unless you really have to!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Home page</title>
<script type="text/javascript">

var uri;
var myWindow;

function openme(uri){
myWindow = window.open(uri, 'myWindow', 'toolbar=0,status=0,width=800,height=600')
myWindow.moveTo(0,0);
if (navigator.appVersion.indexOf("Mac",0)>0) {
myWindow.resizeTo(screen.availWidth,screen.availHeight);
} else {
myWindow.resizeTo(screen.width,screen.height);
}
myWindow.focus();
}

</script>

</head>

<body>
<h1>Index Page</h1>
<a href="javascript:void(0)" onClick="javascript:openme('home.html')">open me</a>
<p>This opens a new browser window</p>
</body>
</html>

No comments: