Click to See Complete Forum and Search --> : Cheeky Javascript request


SMcClure34
04-29-2003, 04:32 AM
I'm new here, and I just wanted to ask if someone could help me. For my website, I have a Javascript code which launchs my website in full-screen, and content in this website is launched in pop-up boxes. I have codes for these. However, the site is optimized for those with 800X600 monitors, and I've found that many people have a higher resolution.

I was wondering, would it be possible to have a javascript code which would detect the users resolution. If its higher than 800X600, it would launch in a window, If it IS 800X600, it would be displayed full screen, and if its lower, it would display an error message?

I've got the coding for the full-screen, pop-up window and error box sorted, its just the screen res. detection. Is it possible anybody? Thanks a lot for your help.

SMcClure34
04-29-2003, 04:41 AM
If it'll help, here are the Codes I already have:

FULL SCREEN:
<script language=JavaScript>
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,"fullscreen=yes");
}
//-->
</script>

POP-UP WINDOW:
<script language=JavaScript>
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>

ALERT:
onClick='alert("Your monitor resolution must be set to 800 X 600 or higher")'

SMcClure34
04-29-2003, 04:52 AM
OK, I'll save you the thinking. I found a resolution detecting script on Javascript source, and inserted the other scripts. Would this work?

<script language=Javascript>
<!-- Begin
if (screen.height >= 600 && screen.width >= 800) {
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
else {
if (screen.height == 600 && screen.width == 800) {
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,"fullscreen=yes");
}
else {
alert("Your monitor resolution must be set to 800 X 600 or higher");
}
}
// End -->
</script>

Padrill
04-29-2003, 05:04 AM
Take the function declaration out of the if else structure and call them by name.

function xyz( a, b, c) {
...
}

if (condition) xyz(arguments)
else if ...
else ... alert('');

SMcClure34
04-29-2003, 05:07 AM
Like this?

<script language=Javascript>
<!-- Begin
if (screen.height >= 600 && screen.width >= 800) {
MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
else {
if (screen.height == 600 && screen.width == 800) {
MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,"fullscreen=yes");
}
else {
alert("Your monitor resolution must be set to 800 X 600 or higher");
}
}
// End -->
</script>

Padrill
04-29-2003, 06:01 AM
You're a very bad case, aren't you. In your case strip everything off except the window.open line

SMcClure34
04-29-2003, 06:25 AM
Like this?

<script language=Javascript>
<!-- Begin
if (screen.height >= 600 && screen.width >= 800)
{ window.open(theURL,winName,features);
}
else {
if (screen.height == 600 && screen.width == 800) { window.open(theURL,winName,"fullscreen=yes");
}
else {
alert("Your monitor resolution must be set to 800 X 600 or higher");
}
}
// End -->
</script>

pyro
04-29-2003, 07:51 AM
Something like this will give you more luck:

<script language="javascript" type="text/javascript">
<!-- Begin
if (screen.width > 800) {
window.open(theURL,winName,features);
}
else if (screen.width == 800) {
window.open(theURL,winName,"fullscreen=yes");
}
else {
alert("Your monitor resolution must be set to 800 X 600 or higher");
}
// End -->
</script>

SMcClure34
04-29-2003, 08:25 AM
Hmmm, I've put it in, but I still cant figure out whats wrong. Take a look at http://www.nettoon.co.uk/test.html or http://www.freewebs.com/nettoon/test.html .

pyro
04-29-2003, 08:32 AM
You aren't defining your variables (theURL, winName, features) Try this:

<script language="javascript" type="text/javascript">
<!-- Begin
var theURL = "yourpopup.htm";
var winName = "popupwin";
var features = "height=800,width=600";

if (screen.width > 800) {
window.open(theURL,winName,features);
}
else if (screen.width == 800) {
window.open(theURL,winName,"fullscreen=yes");
}
else {
alert("Your monitor resolution must be set to 800 X 600 or higher");
}
// End -->
</script>

SMcClure34
04-29-2003, 10:42 AM
A little problem. Hopefully the last one :-S The webpage varies. Is there anyway I can sort that out? Perhaps changing the href in the BODY too?

pyro
04-29-2003, 10:53 AM
I'm not sure I understand what you mean... could you come again? Does the page vary depending on if the res is 800x600 or something else?

SMcClure34
04-29-2003, 10:57 AM
No no. There are two links wwhich will use the same function, but they just link to differnt webpages. I used to enter a special href with my pop-up window code:

(e.g.
<script language=JavaScript>
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<body>
<img SRC="example.gif" BORDER=0 onclick="MM_openBrWindow('example.html','','width=400,height=350')" href="javascript:;" a width="100" height="100">
</body>
)

I was wondering, is there anyway to alter the link with the screen res. dectection code?

pyro
04-29-2003, 11:07 AM
I think that this is what you want...

<script language="javascript" type="text/javascript">
<!-- Begin
function openwin(theURL,winName,features) {
if (screen.width > 800) {
window.open(theURL,winName,features);
}
else if (screen.width == 800) {
window.open(theURL,winName,"fullscreen=yes");
}
else {
alert("Your monitor resolution must be set to 800 X 600 or higher");
}
}
// End -->
</script>
</head>
<body>
<a href="example.html" onclick="openwin(this.href,'','width=400,height=350'); return false;"><img src="example.gif" border=0 width="100" height="100">

SMcClure34
04-29-2003, 11:18 AM
That So Bloody Works!! THANK YOU THANK YOU THANK YOU! You are amazing!

pyro
04-29-2003, 11:22 AM
You're welcome! :D