Link to home
Start Free TrialLog in
Avatar of sciber_dude
sciber_dudeFlag for United States of America

asked on

Breaking out of a Frame VBScript - onload logout when cookie expires

I have a page (2.asp) that loads within the "Mainframe" of an existing page (frames.asp). When 2.asp loads, I want this page to check if the permission in cookie is set for the page to load. If found false, it should break out of the frame and load logout.asp

The cookie was first set on the loginnow.asp with this code.
<%response.buffer=true
response.cookies("module").Expires=date + 1
response.cookies("module")("permission")= "yes" %>

On 2.asp the onload() function body checks if the permission is still "yes"

<script type="text/vbscript">
function onload()
 permission1=request.cookies("module")("permission")
  if permission1 = "" or permission2="no" then
    javas()
  end if
end function
</script>

javas() is a javascript which is

<script type="text/javascript">
function javas()
{
  if (window.top != window.self)
   {
    window.top.location="logout.asp"
   }
}
</script>

Unfortunately, this doesnt work! Is there a way to break out of a frame in VBScript. Also the error is on Request.cookies !!

Is there is something wrong in my code? I would appreciate if you can help me out with this.
Avatar of herongan
herongan

You try following code:

=============================================
<%response.buffer=true
response.cookies("module").Expires=date + 1
response.cookies("module")("permission")= "no"
%>

<html>

<script language="vbscript">
function window_onLoad()
permission1="<%=request.cookies("module")("permission")%>"
 if permission1 = "" or permission1="no" then
   javas()
 end if
end function
</script>

<script language="javascript">
function javas()
{
   top.window.location="logout.asp"
}
</script>

<body>
</body>
</html>

=============================================
If you want to check the current window is the top or not, you can use following code.

if (self!=top) // self isn't the top
{
  top.window.location="logout.asp"
}

But i don't know why you need to check it?

Hope can help!
"request" is a server-side object.
Your VBScript is a client-side script.
For this reason, the error will occur when you trying to get a cookie via "request.cookies".
Avatar of sciber_dude

ASKER

Herogan,
Thank you for your replies. It did help me find the solution. "request" is a server-side object. This was cause of the problem.

I have found the solution to my problem:-

1. I've included the following line to 2.asp before <HTML> tag
<!--#include file="checkpermission.asp"-->

2. I have created a new page called checkpermission.asp and have written the following code
<%
response.buffer=true
permission1=request.cookies("module")("permission")

if permission1 = "" or permission1 = "no" then
 Response.Redirect "logout.asp"
end if
%>

3. On the logout.asp page, I have added the following Javascript which has an 'onload' function. This breaks this page out of the frames.
<script type="text/javascript">
function javas()
{
 if (window.top != window.self)
  {
   window.top.location="logout.asp"
  }
}
</script>

The advantage of this technique is that I dont have to write 'permission checking' code on all the pages in the module. Adding just the #include line will do the job.

This is the first time I have asked a question on this forum. Even though your answer has not given me the exact solution to my question, I should give you credit for showing me the right direction.

Thanks.
How do I award the points / grade?
ASKER CERTIFIED SOLUTION
Avatar of herongan
herongan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Besides it, the "Available Question Points" will auto increase 5 points for each day.
Or you can spend $$ to buy.
Thank you for you help!