PDA

View Full Version : Does Javascript block a Session var???


JVRudnick
01-23-2003, 01:34 PM
Hello all..
I'm using a simple javascript window.open script to pop open a window in an ASP/IIS5/IE page. The page that opens up in that new window is a simple ASP page. That works, no problem.

What I'm unable to do, is to pass that page a simple Session Variable, that holds the name of that logged in web vistors team (this is a baseball assoc. site). It *seems* that using this javascript script will NOT pass a Session var????

IT should be easy, and I've not succeded...

Can someone offer this workaround -- how do I create a normal var, from a Session var, then pass it to the page so that the title can read (for instance) -- "Toronto Blue Jays Team Roster" ???

If you follow this can you help? Oh, and yes, I've tried opening up the plain asp page, and yes, the team name DOES show...but not when it's opened up in the pop up window?

Jim Rudnick

beetle
01-23-2003, 03:32 PM
Are you passing the session var with the querystring?

such as...

www.domain.com/page.htm?sid=a1b2c3d4e5

??

JVRudnick
01-23-2003, 04:01 PM
no....I'm not...

guess I could, I know how...

but my question is more 'academic'

why is it NOT possible to use a session var on a popup page?

can't get it to work...but shouldn't it work???

Jim

arnyinc
01-23-2003, 04:24 PM
It works for me.

setvar.asp

<html>
<body>
<%
session("myvar")="test variable"
%>
<a href="#" onclick="window.open('getvar.asp')">my link</a>
</body>
</html>


getvar.asp

<html>
<body>
<%
response.write session("myvar")
%>
</body>
</html>


Are you using window.open with a file or are you dynamically creating a file? The latter would cause anything between the <% %> to disappear. It will show up if you do a "view source" but it won't be processed.

JVRudnick
01-23-2003, 07:49 PM
Here's what I'm using on the parent page...(sessoin var already established, it's session("teamname")...

Up top...

<script language=Javascript type="text/Javascript">

function newWindow(fishStory) {

fishWindow = window.open(fishStory, 'fishWin', 'toolbar=no, location=no, scrollbars=yes, width=650, height=560, top=80, left=120')
fishWindow.focus()
}
</script>


then when the user clicks this button...



<a href="javascript:newWindow('edit/rosters/<%=Session("teamname")%>roster.asp')">


and that page, roster.asp the title looks like this...


<U><B>Roster for <%=Session("teamname")%>!</B></U>



When run on it's own, roster.asp SHOWS the session var...as it should.

When run inside that popup window, it does not show...the line becomes "Roster for !"

???

Jim

whammy
01-23-2003, 09:15 PM
Does this popup reside in the same domain?

arnyinc
01-23-2003, 09:49 PM
I'm not sure then. :confused: When you do a view source, does it show up as:

<U><B>Roster for !</B></U>

or

<U><B>Roster for <%=Session("teamname")%>!</B></U>

whammy
01-23-2003, 10:49 PM
P.S. This code:

<a href="java script:newWindow('edit/rosters/<%=Session("teamname")%>roster.asp')">

If your "teamname" variable were "Cow", for instance, would open:

edit/rosters/Cowroster.asp

You are probably already aware of that, but after reading your comment about "roster.asp", wanted to double-check.

If in fact it is opening "roster.asp", then of course no session variable is being set, since it isn't showing up as part of the page name as you have it coded.

JVRudnick
01-23-2003, 11:42 PM
When I view source, it shows -- as it should -- the line --


<U><B>Roster for <%=Session("teamname")%>!</B></U>


And yes, I realize that I'm using the same session("teamname") as a part of the filename...as I should be and yes it opens up the correct page as well...this is a red herring, folks...and not important..

Anyone else? It MUST be the javascript window.open puppy that's making this fail...

Mustn't it?

Jim

whammy
01-23-2003, 11:46 PM
Do you have cookies disabled? Classic ASP depends upon cookies for sessions.

JVRudnick
01-24-2003, 12:41 AM
Sorry...but this is a programmer asking here...

'course they're enabled....

I understand all the vars, guys...and they're all SET TO WORK...

But javascript is denying me the session var...

Can *anyone* else help here...I dont' need more "did you check on..." thingys....

Everything is set to work...

'Cept it's not....

And I don't mean to sound 'pissed' at anyone here..but of course it should be displaying..and it's not!!!

Jim

whammy
01-24-2003, 12:47 AM
Actually, I'm a programmer too (for a living - I use ASP every day). And I AM trying to help... but I'm also just trying to make sure you haven't missed anything simple - believe me I work with about a dozen other developers and it happens all the time, usually a bug in a complex application turns out to be a typo or something of the sort. ;)

It looks like your popup is in the same domain, so I'm clueless as to why a session variable wouldn't be working if you have cookies enabled, and you have determined that the Session variable is being set.

I just tried the following test:

setsession.asp:

<% @Language="VBScript" %>
<% Option Explicit %>
<%
Session("foobar") = "Yay!"
%>
<html>
<head>
<title>Test</title>
<script type="text/javascript">
<!--
function openWindow() {
window.open('sessiontest.asp')
}
// -->
</script>
</head>
<body>
<form id="blah" action="javascript://">
<input type="button" value="Open a window" onclick="openWindow()" />
</form>
</body>
</html>


sessiontest.asp:

<html>
<head>
<title><% = Session("foobar") %></title>
</head>
<body>
<% = Session("foobar") %>
</body>
</html>


And it works, so apparently it's definitely not a problem with javascript interfering with the session variable. Is the page you're opening defined as being in a different virtual directory in IIS, or is it the same domain? If it's not the same domain that could conceivably be a problem. :)

P.S. I also just tested it by moving the 'opened' page around a bit, in directories above and below the first page, and adjusting the file path accordingly - still no problem. JavaScript isn't the demon here, it's something else.

Can you post the code?