Avatar of Gareth_Pointon
Gareth_Pointon asked on

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
ASPJavaScriptVB Script

Avatar of undefined
Last Comment
Gareth_Pointon

8/22/2022 - Mon
Scott Fell

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.
ASKER
Gareth_Pointon

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.
Scott Fell

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?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
Gareth_Pointon

The POPUP has a window name so can we not just call that window to close?
Julian Hansen

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.
ASKER
Gareth_Pointon

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Julian Hansen

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.
Scott Fell

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.
COBOLdinosaur

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&
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
Gareth_Pointon

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
ASKER CERTIFIED SOLUTION
Scott Fell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Gareth_Pointon

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>"
Scott Fell

>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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Gareth_Pointon

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....
Scott Fell

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.
ASKER
Gareth_Pointon

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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Scott Fell

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.
Julian Hansen

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?
G_H

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Scott Fell

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.
ASKER
Gareth_Pointon

Sorry been on holiday. Going to try this week...