Forum Moderators: open

Message Too Old, No Replies

Passing JavaScript variables through SSI

will this work?

         

too much information

8:54 pm on Jan 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to send the output of a JavaScript to a text file.

I have no problem writing to a file with ASP, but I don't want to do a redirect to pass variables in a querystring because it would cause an infinite loop. (the way I am set up) But if I could call an ASP function with an #include I have no problem using a querystring.

So is it possible to pass the javascript variables to an include such as:

<script ...>
JSvariable = "some value"
if ...
{
<!--#include file="scripts/write.asp?" & JSvariable-->
}
</script>

Clearly I am not sure about how to do this. Can anyone give me some clues?

IanTurner

10:31 pm on Jan 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



My understanding is that you can't do this.

The order of processing is such that it wouldn't work the #include is processed first, followed by the ASP and then the client side Javascript.

If you want the output of the Javascript written to a server side file then it can be done using a pop-up or a hidden frame which loads an ASP file.

RossWal

11:43 pm on Jan 6, 2004 (gmt 0)

10+ Year Member



Where is the text file intended to be? Server or client machine?

too much information

4:32 pm on Jan 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because the #include is a conditional in the javascript I thought it might execute after the fact.

Anyway...

The text file is on the same server as the site. I have an #include that does my tracking for me, but I want to have a separate log which adware people have installed.

The only script that I have found that determines the existance of adware is in Javascript and outputs the results to the page. I don't mind using a pop-up, I can have it close after it is done, which would be very quick. How could I pass the info to a pop-up?

(I'm not very good at my JavaScript. I know the basics, but it isn't as easy to find help online as it is for VBScript and ASP)

shasan

5:01 pm on Jan 7, 2004 (gmt 0)

10+ Year Member




My understanding is that you can't do this

Yeah, you're missing a layer.. you need the ASP in between to write to a file on the server.

passing the info to the popup: can't you pass the info in the URL for the popup?

RossWal

5:24 pm on Jan 7, 2004 (gmt 0)

10+ Year Member



Another possibility would be to place the value either in a hidden input field or in a cookie. Then process it from the asp script upon returning to the server, that is if you're sure they'll be hitting your server before leaving the site (in the case of the hidden field) or returning to your site at some point (in the case of the cookie).

Also, in IE, you can post directly from a client side javascript script to a web server, but I think this functionality is limited to IE. In other words you would post data to myloggingpage.asp, which would simply do the logging, transparent to the client.

HTH
Ross

IanTurner

5:30 pm on Jan 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If I was doing this I would do something like this

function Popup(URL) {
day = new Date();
id = day.getTime();
window.name="main";
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300');");
eval("page" + id + ".moveTo(0,0);");
eval("page" + id + ".blur()");
window.focus();
}

Where the URL is "my-file.asp?var=javascriptvariablevalue"

Then in my-file.asp

ASP Write File Code
<head></head>
<body onload="self.close();"></body>

bsterz

5:48 pm on Jan 7, 2004 (gmt 0)

10+ Year Member



How about:

<script language="JavaScript" type="text/JavaScript">
var SomeVar='Hi There';
document.write('<script language="JavaScript" type="text/JavaScript" src="dynamicpage.php?var=' + SomeVar + '"><\/script>');
</script>

Now in dynamicpage.php:
alert('<?=$_GET["var"]?>');
// You could just as easily write this var to a text file.

Kinda convoluted...probably regret posting it..but it looked kinda kooky and fun.

Bill

too much information

6:36 pm on Jan 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Kinda convoluted...

Not really, that's what I was looking for, but from what I have read online I'm not sure it would work.

I'll try both and see what works. I'm just afraid that the pop-up blockers will defeat the pop-up, especially since I am trying to log visits from software that serves pop-ups. And if someone does not know that the software is on their machine, they are probably using a blocker to control it.

bsterz

6:54 pm on Jan 7, 2004 (gmt 0)

10+ Year Member



You don't have to do a popup for that to work..it all happens from the one page.

too much information

7:40 pm on Jan 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bsterz - that works great, thanks!

Now I just need to work on the formatting...

RossWal

10:30 pm on Jan 7, 2004 (gmt 0)

10+ Year Member



Very clever, bsterz. Thanks for sharing it.

IanTurner

12:41 am on Jan 8, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yep thats downright sneaky