Call Function ASP

Hi,

I have a popup window on my internal intranet system that what the session times out is loading the login page.

I would like to user security script to fire a function to close the popup and redirect the user on the main browser window.

If the popup is not open then there is no problem as the User security check script redirects on the main windows anyhow.

Thanks
Gareth_PointonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
This is a little hard to follow.  Do you have serverside vb script or client side js script that checks to see if you are logged in?  If not, then it fires a pop up? probably through javascript?

Somehow in your wording it is not completely clear?

Thank you.
0
Gareth_PointonAuthor Commented:
Hi,

No its a server side script that is just a ASP if Statement. This is not a Java or VB script.

What I would like is for the ASP if Statement to fire a function that will close the POPUP window that is possibly in use or open in the background.

This popup window is a job overview and update window. Please are not closing it do I would like the session time out If statement to fire the POPUP window close function.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
If you have a pop up, chances are it is javascript/jquery or at least that is what you would use to close it.  Remember, your asp and vb code runs on the server before the page even loads.  Once the page loads, you have lost all access to the server.  

If you are running some kind of ajax function to see if the session is alive, then you are using javascript or jquery.  

To answer your question, the only way to close a pop up is sending either a get or post back to the server.   You would probably want to do this with javascript or jquery and not hit the server.

What is the code you are using to make the pop up?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Gareth_PointonAuthor Commented:
The POPUP has a window name so can we not just call that window to close?
0
Julian HansenCommented:
You can't do that.

Once the ASP page has completed and rendered the HTML to the browser it ceases to exist. The only way ASP can become active again is if a post or get is sent to the server.

You can't use ASP to interact with the browser. ASP can render the javascript that will interact with the browser but cannot interact directly.
0
Gareth_PointonAuthor Commented:
I know.

Thats why I want the <%If CALLJAVASCRIPT %> statement to call the Javascript to close the window.

I'm not asking the ASP script to close it. I'm asking the Javascript to close it but to be called with in an ASP IF statement.
0
Julian HansenCommented:
Ok you are confusing us - you said

No its a server side script that is just a ASP if Statement. This is not a Java or VB script.

Thats why I want the <%If CALLJAVASCRIPT %> statement to call the Javascript to close the window.

How exactly do you envisage this working?

ASP can output the javascript to do the work - but that does not activate until after the ASP script terminates.

What you are suggesting (if I understand you correctly) can't be done - you can't call the javascript function from ASP.
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Please render your page with the pop up, view source, then copy and paste the code. Or provide us with a sample link.

ASP or VB is not in the solution here.  It is just a matter of a javascript or jquery function needed to listen for something, and based on some criteria, close the pop up.

I understand the confusion but asp/vb work differently than js.
0
COBOLdinosaurCommented:
If I understand this correctly you are going to be trying to use javascript on the main page to close a popup when the main page is closed.  There is no reliable way to insure that such an action would always take place.  

Cd&
0
Gareth_PointonAuthor Commented:
OK Guys .. Sorry about the confusion.

At present I have :

<%
If (Session("ETuserGood") = False or IsNull(Session("ETuserGood")) = True) and Request.ServerVariables("PATH_INFO") <> "/login.asp" then
URL=Request.ServerVariables("server_name")
	Response.Redirect "http://"&URL&"/login.asp"
End If

If (Request.ServerVariables("PATH_INFO") = "/login.asp" and Session("ETuserGood") = True) Then
URL=Request.ServerVariables("server_name")
	Response.Redirect "http://"&URL&"/index.asp"
End If
%>

Open in new window


The issue is that if the user has the details page open (POPUP window) then they get redirected in the popup window to the login page and not on the main window.

This is confusing the users as they then have a load of windows open.

I would like the POPUP window to be closed and then the main.window to be reloaded. This will then take them back to the login page correctly.

I hope thats clear now.

Thanks
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I would suggest re thinking what is going to to start with and not have pop up windows at all.   You will see on newer sites the trend is to have a modals.

To answer your question, lets say you have a pop up on log in pop up.  If you try out this code, you can click the log in link, then below click the Simulate Log out link and the window closes.  

I do more in jquery then pure js. But notice the window is called login_window and that is what is used to open and close.  The close is via the function, close_login_window.  

In your asp, I think you should be able to do something like below.  This should be either in your head section if that is where the rest of your js is or at the bottom of the page above the closing body tag.  
<%
if something=True then
   response.write "<script> close_login_window()</script>"
end if

%>

I do think a better way is to avoid having pop up's at all.


<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Padas Log In</title>
<SCRIPT>
    
function login_window()
{
   login_window = window.open("",
     "LogInWindow","status=1,width=500,height=500");
   login_window.document.write('<H1>Please Log In</H1><input name="pass"><br><button>Submit</button>');  
}

function close_login_window()
{
   login_window.close();
}
   
</script>
</head>
<body>
<P><A href="javascript: login_window()">Log In</A></P>
<P><A href="javascript: close_login_window()">Simulate Log out</A></P><P>
  
</body>
</html>

Open in new window

I think the problem with the code above is if you are calling the close on a separate page, this will not work. (or page refresh)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gareth_PointonAuthor Commented:
I agree the modals would be good but I'm again finding people are clicking out side the box and loosing work as this is then closing the modals down.

I cannot get the script to be fired in the ASP using the suggested  response.write "<script> close_login_window()</script>"
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
>I cannot get the script to be fired in the ASP
That is because I don't believe you can have page 1 close page 2.   The code I gave you only works on the same page.  I probably shouldn't have posted it as a solution.  But it does help show what you can and can't do.  

Why does the log in need a pop up though?  I'm confused on that part.  Does the pop up have some type of timer?  if that is the case, the pop up can use ajax to test for the session.  If not logged in, then self close.
0
Gareth_PointonAuthor Commented:
Hi,

The login is not in a popup. When you log in its on the main windows and you can navigate through the site as normal.

The issue comes when they load the job overview window that is a popup. This is where they can amend the jobs and so on. They then should close that window down but are not doing.

If they leave that window open and leave the system for some time then the session times out.  When they then go back to that page it then takes them to the login window and their then using the system in the small popup window.

I know its user training but when people just dont do something there is nothing you can then do.

Maybe what I should do is get the system to load the login in a model and then reload the original page....
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Keep in mind you are making statements that you fully understand and I don't.

>The issue comes when they load the job overview window that is a popup

That pop up can do an ajax call to check if logged in or have a js timer.  If either logged out or timer runs out, close it's self independent of the other windows.
0
Gareth_PointonAuthor Commented:
mmm .. a JS timer sounds good ...

Can that also warn the user they are about to be logged out?

If so is there anywhere that has a sample script please.

thanks
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
One of the problems as you know the session can time out for other reasons besides time so you are making an estimate.  If  you have your server session set for 15 minutes, I would set the js timer for a little less.  

I use this timer countdown http://keith-wood.name/countdown.html.  
They show this sample to display text after the countdown reaches zero
$('#expireMessage').countdown({until: shortly, 
    expiryText: '<div class="over">It\'s all over</div>'}); 
     
$('#expireMessageStart').click(function() { 
    shortly = new Date(); 
    shortly.setSeconds(shortly.getSeconds() + 5.5); 
    $('#expireMessage').countdown('option', {until: shortly}); 
});

Open in new window

Instead of displaying text, just call a js or jquery function to close the self window.

I have something similar where I do an ajax call to a blank asp page that just tests if the session is still alive.   If it is not, I send a modal to log back in.
0
Julian HansenCommented:
Why not just put a meta-refresh tag in the header of the popup - assuming it is in a separate window - and have that redirect the page when it times out?
0
G_HCommented:
One of the problems as you know the session can time out for other reasons besides time so you are making an estimate.  If  you have your server session set for 15 minutes, I would set the js timer for a little less.

If the popup does an Ajax call to the server every 5 minutes, then this would probably keep the session alive..?

That excepted, would it not be possible (excuse the quasi-code) to send this to the popup if the session had timed out:

<script>
window.parent.AjaxfunctionToReloadPageWithTheLoginPage;
window.self.close
</script>

Open in new window


This is similar to what I do when my uploadify popup has finished it's queue...

GH
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
then this would probably keep the session alive..?
I does.  It is really the idle time out on the app pool that people forget about that is the cause of premature time outs.  The ajax call would prevent that from happening. If you set the idle time out to 7 minutes and the ajax call is every 5 minutes, it will take  a long time to time out.
0
Gareth_PointonAuthor Commented:
Sorry been on holiday. Going to try this week...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.