In my site I am applying a stylesheet depending upon the resolution of the viewer's monitor. By using screen.width
in javascript i do this. But now I have a doubt that can I use the same technique to change the whole content of the site depending upon the resolution, i.e, for higher resolutions more contents and for lesser, fewer. Or you please suggest me some other technique to do this.
views:
243answers:
3
+4
A:
You could detect the resolution and use this to apply a class to the body of your page and use this to tell CSS to show/hide certain columns. I can provide sample code if you let me know which framework / no framework you're working with.
Here is reallly basic example in plain javascript:
window.onload = function(){
var resolution = 'res'+screen.width;
document.getElementsByTagName('body')[0].className= resolution;
}
This also has the advantage that a page will always display regardless of whether JavaScript is enabled or not. If JavaScript is enabled you can tailor the page to the resolution, if not the user will still see your content.
seengee
2009-12-02 14:22:14
i am using php and following MVC architecture and implementing my own framework. i like to try your idea.
Goysar
2009-12-02 14:51:11
boo to window.onload!
David Murdoch
2009-12-02 14:52:18
haha! yep, i agree. just an example like i said but odds are he will be using a framework with a better dom ready style implementation
seengee
2009-12-02 15:02:28
+1. Also, take a look at SmugMug as they have this whole page scaling thing figured out... http://philipjoep.smugmug.com/Other/Colorado/
Steve Wortham
2009-12-02 23:37:28
A:
Have your initial page load return an empty container and execute an ajax call that will populate it with the content. The ajax call can pass the resolution as a parameter so you can return the appropriate content accordingly.
Janek
2009-12-02 14:27:22