sciber_dude
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=d ate + 1
response.cookies("module") ("permissi on")= "yes" %>
On 2.asp the onload() function body checks if the permission is still "yes"
<script type="text/vbscript">
function onload()
permission1=request.cookie s("module" )("permiss ion")
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="logou t.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.
The cookie was first set on the loginnow.asp with this code.
<%response.buffer=true
response.cookies("module")
response.cookies("module")
On 2.asp the onload() function body checks if the permission is still "yes"
<script type="text/vbscript">
function onload()
permission1=request.cookie
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="logou
}
}
</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.
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="logou t.asp"
}
But i don't know why you need to check it?
Hope can help!
if (self!=top) // self isn't the top
{
top.window.location="logou
}
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".
Your VBScript is a client-side script.
For this reason, the error will occur when you trying to get a cookie via "request.cookies".
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.cookie s("module" )("permiss ion")
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="logou t.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.
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.cookie
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="logou
}
}
</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.
ASKER
How do I award the points / grade?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Besides it, the "Available Question Points" will auto increase 5 points for each day.
Or you can spend $$ to buy.
Or you can spend $$ to buy.
ASKER
Thank you for you help!
==========================
<%response.buffer=true
response.cookies("module")
response.cookies("module")
%>
<html>
<script language="vbscript">
function window_onLoad()
permission1="<%=request.co
if permission1 = "" or permission1="no" then
javas()
end if
end function
</script>
<script language="javascript">
function javas()
{
top.window.location="logou
}
</script>
<body>
</body>
</html>
==========================