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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending javascript with asp 1

Status
Not open for further replies.

derwent

Programmer
May 5, 2004
428
GB
Wasn`t sure which forum to use so I gambled on this one...

I want to see the screen resolution of our users say over just 1 month to gauge what most people are using and was going to send to DB or write to a simple file.

So I need to use clientside to grab the screen res and serverside to send to file. My problem is that when I try to write to file it displays my javascript instead of the output, i.e.

Code:
<script> 
var w = screen.width; 
var h = screen.height;

document.write(w+'x'+h);
	
</script>

<%
MyFile = Server.MapPath("screenres.txt")

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set TSO = FSO.OpenTextFile(MyFile, 2)

TSO.write "<script>document.write(w+'x'+h);</script>" & vbcrlf

TSO.close
Set TSO = Nothing
Set FSO = Nothing
%>

sends to the text file "<script>document.write(w+'x'+h);</script>"

but what I need is for example "800x600"

Is there a way to make asp and javascript work together?
 
The logic does not stick. Here is a way to construct the (asp) page. (Beef it up with "good" practice.)
[tt]
<%
bsubmitted=0
if request("w")<>"" and request("h")<>"" then
MyFile = Server.MapPath("screenres.txt")
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
'Set TSO = FSO.OpenTextFile(MyFile, 2)
[blue]Set TSO = FSO.OpenTextFile(MyFile, 8, true)[/blue]

'TSO.write "<script>document.write(w+'x'+h);</script>" & vbcrlf
[blue]TSO.write request("w") & "x" & request("h") & vbcrlf[/blue]

TSO.close
Set TSO = Nothing
Set FSO = Nothing
bsubmitted=1
end if
%>
<html>
<head>
<script language="javascript">
var b="<%=bsubmitted%>";

window.onload=function() {
var w = screen.width;
var h = screen.height;
document.getElementById("divid").innerHTML=w+"x"+h;
document.formname.w.value=w;
document.formname.h.value=h;
if (!b) {document.formname.submit();}
}
</script>
</head>
<body>
<div id="divid"></div>
<form name="formname" method="post">
<input type="hidden" name="w" />
<input type="hidden" name="h" />
</form>
</body>
[/tt]
 
I don`t understand how this would work?

The asp loads then the javascript submits the form, but as the asp has already loaded it can`t find the request("w") can it?
 
The first time you load the page, the code in JavaScript gathers the screen resolution, puts them into two variables and reload itself while submitting these variables to itself, then it will be able to read the variable values in the ASP code and write them into the text file.

So you are right, basically what happens that this page has to be called twice in order to get the screen information but it does that automatically.
 
Oh right, thanks for that. Looking at the source code however the variables haven`t been read by the asp, and the text file is blank.
 
>I don`t understand how this would work?
>Looking at the source code however...
I wouldn't blame you. But, by purely looking at code and come up with an understanding of how things perform require a lot more training.
 
far too much ASP in that to be in the JS forum ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I don't think so unless one wants to play ping-pong which many become very good at. It is rather far too much asp and jscript at the same time. I should put a copy-right notice there like others being good at as well.
 
huh ping-pong , copy-right , what you on about it was a joke tsuji, notice the winking smilie

whats jscript anyhow?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
nah I can`t get it to work tho. The text file remains blank.
 
Make sure it is an ascii text file. Or if you have done nothing special on the textfile, use system default which is probably unicode.

>Set TSO = FSO.OpenTextFile(MyFile, 8, true)
[tt]Set TSO = FSO.OpenTextFile(MyFile, 8, true, [blue]-2[/blue])[/tt]
 
>[self]if (!b) {document.formname.submit();}
[tt]if [blue](b=="0")[/blue] {document.formname.submit();}[/tt]
 
I've got the quick testing done, and after the last correction, it works fine for me. (That part was due to my change of mind at last minute of posting to not relying on boolean and use a less taxing simple string.) How is it for you?
 
It works thanks a lot. By the looks of it so far (10 mins) most people are on 1024x768.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top