Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recording client screen resolutions 1

Status
Not open for further replies.

FesterSXS

Programmer
Feb 4, 2002
2,196
GB
I am looking for a way to record the various resolutions that users of my site are using. I know how to detect their resolutions using Javascript on the client side
Code:
var pageWidth = screen.availWidth;
var pageHeight = screen.availHeight;
I am just after a means to get that info up to the server so I can save it into a text file or a database. I only want to record the data once for each visit to the site, not each time the user goes to a new page within the site.

I guess I will get repeat values when the same user comes back to the site another day but I am not too bothered about that.

Any ideas guys and girls??
Tony
reddot.gif WIDTH=400 HEIGHT=2 VSPACE=3

 


What you can do is look in the db, for that resloution, and add to another column a number count to that resloution, so basicly you will have something like..

user_res | res_count
864 10

This is how you get screen res..
<%@ Language=VBScript %>
<SCRIPT Language=VBScript>
Sub window_onload
Document.Write(screen.height)
End Sub
</SCRIPT>



 
That doesnt get me the info up to the server though. I can get the resolutions ok but only by using clientside script - I am after a way to either get the resolution info up to the server or have the server detect the resolution of the client - either solution should only give me the info once per visit.
Tony
reddot.gif WIDTH=400 HEIGHT=2 VSPACE=3

 
Well you can get a variable in asp from a <script> im just not sure hoe right at this second.
 
You could write you page links to call a javascript code instead of an actual link. When the user clicks the link, the code could append a querystring to the URL and add the screen dimensions.

The ASP page could then look for this and save it to the database. The ASP page could also return a hidden form field that tells the javascript in the browser the screen dimensions have already been stored for this user, no need to send them again.

<a href='javacript:SubmitURL(&quot;GetNextPage.asp&quot;);')>Go Here</a>

<script language=JavaScript>
function SubmitURL (sURL) {
/*
Place code to check and see if the screen info needs to be sent to the server.
If it does, add the info to the end of the url
EX. sURL = sURL + '?width=600&height=400';
window.location = sUrl;

*/
}
</script>

 
There is a third party utility. If you go to google and type in &quot;BrowserHawk&quot; it will take you to the page. There is another way to do it also. I read it in a book I have but I can't remember how. It wasn't really on my mind at the time. If I run across it again, I'll post it here for you. In the mean time, here is a link I found for ya on the subject:


Hope it does you a little good. Rob
Just my $.02.
 
Hi guys,

Sometimes we all forget the simplest techniques the more we learn the complex stuff.

Why not just use an initial index page that just gets the clients screen size, then use the javascript to throw the user to the next page where you can store the information and display the first page they see.

This happens too quickly for the end user to even notice! AND its extremely simple!

ie...
// *** THIS IS INDEX.HTML - THE FIRST DEFAULT LOADED PAGE *** //
<script language=&quot;javascript&quot;>

var pageWidth = screen.availWidth;
var pageHeight = screen.availHeight;

self.location.href = 'index.asp?width=' + pageWidth + '&height=' + pageHeight;


</script>


// ***** INDEX.ASP ***** //

<%

pageWidth = request(&quot;width&quot;)
pageHeight = request(&quot;height&quot;)

.... YOUR DATABASE CODE HERE ...
.. store your screen info ..

... Maybe some cookie stuff here
.. just so you don't keep recording
.. the screen size of the same person..

%>
*** PLACE YOUR HTML STUFF HERE FOR YOUR FIRST PAGE ***


....
Thats it.. voila!

Gorkem.
 
Good morning FesterSXS.

Gorkem has a great suggestion here but just remember, if you have a site with very many pages at all, many of your visitors will never hit your index.htm page.

Many of your visitors will get to your site via a search engine or a bookmark. Keep this in mind when creating your site.

I don't like to use ASP's session object but if you don't have a need to run your site in a web farm, it may be what you are looking for. In the Session_onStart event, redirect the user to the index.htm page and this will ensure it gets hit. Just remember, the events in your global.asa file only get fired when an ASP page is called so you would need to consider changing all the .htm extensions to .asp.

You could also write your code to have your index page redirect back to the page the user first called instead of a default page.


Thanks,

Gabe



 
Hi Gabe - way ahead of you!! :)

the site does have many pages (.asp only) that are linked from external sources but I have built the site so that it will always rebuild itself into the frameset, sending the destination url via a querystring to the frameset page.

Thankyou for your suggestion though

Tony
reddot.gif WIDTH=400 HEIGHT=2 VSPACE=3

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top