Question:
Can javascript/php detect resolution?
laksh
2008-06-09 01:53:48 UTC
Can a script in javascript be made which will first detect the user's monitor resolution n then load the page which i have made for that resolution?

If yes, then will that problem of JAVASCRIPT DISABLED occur as most people have javascript disabled in their browser.

Another question --- Can this script be made in PHP?......If yes, then there will be no burden of script disabled as PHP is a server-side scripting language.
Six answers:
richarduie
2008-06-09 07:21:30 UTC
The better solution would be to create the page for the most popular resolution (1024x768) but give a flexible set of styles that permit it to degrade gracefully, regardless of the actual resolution. The second best approach would be to create styles to make the 1024x768 version perfect and additional, minimum sets of alternate styles for each of the other var resolutions; these alternates would be loaded as needed and, by entering the cascade later, would override the original set with those attributes required by the different resolution. The following sample presumes that you'll do it the way you originally asked, i.e., totally different HTML pages. However, similar logic could be applied to the "style-only" solution.



Note that JavaScript will be required no matter what (even a PHP solution requires a JS, client-side inquiry to get and forward the resolution to your server-side process, and that's WAY suboptimal, since it demands an additional request/response cycle).



The most recent, general estimate I've seen offers a maximum of 15% of surfers who have JS disabled. For those, you give the default page. They've elected not to have the benefits of JavaScript...don't lose sleep over them.













page content goes here



miguela
2016-12-10 15:39:51 UTC
Php Detect Screen Resolution
SakuiWeb.com
2008-06-09 02:50:13 UTC
you can detect screen size as well as browser window size with javascript, i created a tutorial here for all javascript browser related functions. http://www.mikejonesey.co.uk/html/browser_functions.html



Yes the user switching off javascript will stop your script.

as php is server side there is no way of detecting user screen sizes (you could have javascript submit a form to the php but you would still have to use js)



The better option would be to use a style sheet that works the same for all users. Most people use fixed width around 770px however i believe the absolute best design, stretches and shrinks to the users browser.



for example:

AnalProgrammer
2008-06-09 02:02:03 UTC
Aparently you can detect the resolution. See the link.



Unfortunately, whilst php is server side processing, any javascript must be and is client side processing.



You can detect the resolution in javascript and then change the location to a different file.
Rav
2008-06-09 02:17:02 UTC
It is possible in JavaScript.

http://www.pageresource.com/jscript/jscreen.htm



You cannot do it in PHP -- PHP scripts will be executed on the server.



You can pass the width and height to your PHP script using JavaScript executed in the visitors browser.



The best solution will be to make your page "screen-size independent". Assuming the minimal width of 800px is quite secure (Eee PC etc.) If they have more (screen width) -- give them more (page width)
Chandresh Upadhyay
2014-06-06 18:53:35 UTC
function v()

{

var username=document.getElementById("username").value;

var password=document.getElementById("password").value;

var emailid=document.getElementById("emailid").value;

var address=document.getElementById("address").value;

var chk=document.getElementById("chk[]").value;





if(username=="")

{

alert('please enter the username');

document.getElementById("username").focus();





}

else if(password=="")

{



alert('please enter the password');

document.getElementById("password").focus();



}



else if(emailid=="")

{

alert('please enter the emailid');

document.getElementById("emailid").focus();

}



else if(address=="")

{

alert('please enter the address');

document.getElementById("address").focus();

}

else if(chk=="")

{

alert('please select your hobbie');

}





}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...