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.
LVL 11
sciber_dudeAsked:
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.

heronganCommented:
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>

=============================================
0
heronganCommented:
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!
0
heronganCommented:
"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".
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

sciber_dudeAuthor Commented:
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.
0
sciber_dudeAuthor Commented:
How do I award the points / grade?
0
heronganCommented:
After you answer the question, if the answer can help someone to solve the problem. He/She will click "Accept Comment As Answer"(Can you see this word on my posted message?). Then you will gain a expert point.

Hence, pls click the "Accept Comment As Answer" to give me a expert point.HaHa =)

Hero
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
heronganCommented:
Besides it, the "Available Question Points" will auto increase 5 points for each day.
Or you can spend $$ to buy.
0
sciber_dudeAuthor Commented:
Thank you for you help!
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.