Author | Topic: javascript varaible | |
---|---|---|
Allen Lee | javascript varaible on Sat, 16 Apr 2011 17:12:50 -0700 Hi Everyone: My web app currently selects a style sheet based on the web app visitor's screen width - no problem. I want to store the visitor's screen height and width to gather screen size statistics. How do I retreive the variable from javascript? Consider the following: oHtml:put('<script type="text/javascript">') oHtml:put('function getSize() {') oHtml:put(' return screen.width + "," + screen.height;') oHtml:put('}') oHtml:put('</script>') use SCR exclu *** SCR->SIZ:=("javascript:getSize()") What is the proper syntax for the last line ***? | |
Thomas Braun | Re: javascript varaible on Mon, 18 Apr 2011 14:46:14 +0200 Allen Lee wrote: > My web app currently selects a style sheet based on the web app > visitor's screen width - no problem. Your style sheet should be built in a way so it supports any screen size. It generally is a bad idea to build web pages that support specific browsers or screen resolutions etc since you never know what resolution your clients will have and even more important, the resolution (aka browser window size) can change while the page is already loaded. > How do I retreive the variable from javascript? Simple answer - there is no direct way. More detailed answer follows below > What is the proper syntax for the last line ***? There is no "proper syntax" as javascript is executed by the browser and there is no direct way to access any javascript variable from the WAA size. The only thing you can do is to create a form variable and set its value in your javascript. HTML: ----- <input name="scr_resolution_x" type="hidden" value=""> <input name="scr_resolution_y" type="hidden" value=""> Script: ------- document.forms[0].scr_resolution_x.value = screen.width; document.forms[0].scr_resolution_y.value = screen.height; Xbase++ code: ------------- SCR->SIZ:= oHtml:GetVar("scr_resolution_x") + ", " + oHtml:GetVar("scr_resolution_y") Thomas | |
Allen Lee | Re: javascript variable on Mon, 18 Apr 2011 10:18:23 -0700 Thank you, Thomas. Your solution was EXACTLY what I was looking for! I use different style sheets to accommodate different screen sizes. For example, using "%" to increase or decrease the default font size. Can you make a table look good on a 1028 wide and a 1920 wide screen simultaneously with the same style sheet? Would you mind sharing your tips on building a style sheet that supports any screen size? On 4/18/2011 5:46 AM, Thomas Braun wrote: > Allen Lee wrote: > >> My web app currently selects a style sheet based on the web app >> visitor's screen width - no problem. > > Your style sheet should be built in a way so it supports any screen size. > > It generally is a bad idea to build web pages that support specific > browsers or screen resolutions etc since you never know what resolution > your clients will have and even more important, the resolution (aka browser > window size) can change while the page is already loaded. > >> How do I retreive the variable from javascript? > > Simple answer - there is no direct way. > > More detailed answer follows below > >> What is the proper syntax for the last line ***? > > There is no "proper syntax" as javascript is executed by the browser and > there is no direct way to access any javascript variable from the WAA size. > > The only thing you can do is to create a form variable and set its value in > your javascript. > > HTML: > ----- > > <input name="scr_resolution_x" type="hidden" value=""> > <input name="scr_resolution_y" type="hidden" value=""> > > > Script: > ------- > > document.forms[0].scr_resolution_x.value = screen.width; > document.forms[0].scr_resolution_y.value = screen.height; > > Xbase++ code: > ------------- > > SCR->SIZ:= oHtml:GetVar("scr_resolution_x") + ", " + oHtml:GetVar("scr_resolution_y") > > > Thomas | |
Thomas Braun | Re: javascript variable on Tue, 19 Apr 2011 09:22:36 +0200 Allen Lee wrote: > Thank you, Thomas. > Your solution was EXACTLY what I was looking for! Good > I use different style sheets to accommodate different screen sizes. > For example, using "%" to increase or decrease the default font size. Could you pls post an example of how you exactly do this right now? > Can you make a table look good on a 1028 wide and a 1920 wide screen > simultaneously with the same style sheet? This heavily depends on what you understand by saying "looks good" There are two approaches: - Scaling all elements including fonts by using relative units like % or "em"s so the same amount of information fits into the available screen space. - Using fixed font sizes but variable sized containers so more information fits into the screen while using the same fonts. Bith approaches have their problems, basically caused by slight differences in how browsers render content - especially the infamous Internet Explorer and its various box model bugs makes ones life harder than it should necessarily be. Basically, nobody can make the same information look equally good in such different screen resolutions (or, to be more precise, witdth/height ratios) But your approach has a basic problem - you know the screen resolution only after your page has loaded in the browser, so there is no way to send the "correct" CSS when the page loads the first time. Thomas | |
Allen Lee | Re: javascript variable on Wed, 20 Apr 2011 21:29:25 -0700 Hi Thomas: This is what the app does now: <script type="text/javascript"> var css = ""; if (screen.width <= 800) css='wid800.css'; else if (screen.width <= 1024) css='wid1024.css'; else if (screen.width <= 1400) css='wid1260.css'; else if (screen.width <= 1600) css='wid1600.css'; else css='wid1900.css'; document.write("<link href='"+css+"' rel='stylesheet' type='text/css' />"); </script> However, the basic problem of knowing the screen resolution only after the page has loaded in the browser is non-existent because there is an entry/welcome page before the home page that captures the "correct" CSS. | |
Allen Lee | Re: javascript variable on Sat, 23 Apr 2011 10:08:00 -0700 Hi Thomas: In this instant global information age, I do not know where I could get my question answered outside of this forum. I appreciated your quick response and I have always respected your comprehensive knowledge. It is sad to see this forum so rarely used. Why do you think WAA activity has diminished over the years? The last exciting posting was Bruce Anderson's "Something Yummy from Steffen's kitchen" in March 2009. That exposition took my web apps to a greater height that I could not have acheived alone. Thanks, Bruce. Thank you Thomas, once again, for your help. My home is open to you guys whenever you visit Vancouver, Canada. | |
Boris Borzic | Re: javascript variable on Sat, 23 Apr 2011 20:08:27 +0200 Allen Lee <al@infopro.ca> wrote in news:53512406$3c5ede50 $40c3c@news.alaska-software.com: > It is sad to see this forum so rarely used. > Why do you think WAA activity has diminished over the years? Maybe they are now using Xb2.NET Check out the xb2.net NG: news://news.xb2.net Best regards, Boris Borzic http://xb2.net http://sqlexpress.net industrial strength Xbase++ development tools | |
Thomas Braun | Re: javascript variable on Tue, 26 Apr 2011 08:37:46 +0200 Allen Lee wrote: > It is sad to see this forum so rarely used. > Why do you think WAA activity has diminished over the years? Simply because Xbase++ activity has diminished. Xbase++ is (and always has been) a nice product, targeted at a very small part of the programming language market dominated by mainstream languages like C/C++/C#, Java etc... I'm not using Xbase++ for anything else anymore than maintaining one single WAA app... apart from that single application I use c# for smaller things and php for web development. Thomas | |
Thomas Braun | Re: javascript variable on Tue, 26 Apr 2011 16:30:51 +0200 Thomas Braun wrote: > Xbase++ is (and always has been) a nice Please exchange "nice product" with "niche product" (of course Xbase++ is also a "nice" product - but that was not what I wanted to write Thomas |