Click to See Complete Forum and Search --> : Cookie Help
mike_basil
04-08-2003, 03:15 PM
I am trying to utilize cookies to dynamically display links on a page. I have stored a user ID (obtained from a URL) in a cookie. For example, I want to restrict someone with less privileges from accessing some links while others will get to see more links. This will be on a intranet company webpage, is there anyway of doing this????? Thanks for any help.
Generally, there is a way to do almost anything. Perhaps not with JavaScript, but somehow or other...
Anyways, doing this with JavaScript, eh? If you can't use PHP or Perl, then.... Are you parsing the URL with JavaScript? (Using a form on the previous page with the GET method?) If you want what I think you want, you're parsing the URL to see if the user has the features that are to be displayed on the current page. If the user does, continue... If not, redirect to a different page?
mike_basil
04-08-2003, 03:29 PM
I already got the user name out of the URL. I am planning on using Java to see what privileges this person has. Once that is determined, can I dynamically make a page display certain links based on that process?
For example:
I get "John Smith" from the URL. He is a manager, so has access to all sites. Can I write a script that will only take John Smith to sites while blocking others with less authority from having access?
THANKS FOR YOUR HELP!!!
Yah, sure, post the code you already have and I'll fix it up for ya.... (Unless it's a lot harder than it seems. But even then I'll help you.)
mike_basil
04-08-2003, 03:42 PM
The problem is that I don't have anything yet b/c I don't know if its possible. I have the Script that obtains the user name. I don't know where to start with the next part. Does anyone have any examples of this?
Which are you using: server-side or Javascript to parse the URL to get the user name? If server-side, which language? If Javascript I need to see that code. If PHP (a server-side) use something like this in your <head> tag:
<?PHP $user="theUserNameGottenFromURL";
echo ("<script language='Javascript'>
if("$user"=='John Smith'){ document.links['linkName'].href='thePageToSee.html';}
else if("$user"=='Different Name'){ document.links['otherLinkID'].href='otherPageToSee.html';}
else { location='aPageForNonUsers.html';}");
?>
Just keep adding as many else if's as you want.
mike_basil
04-08-2003, 03:55 PM
I am using JavaScript to parse the URL. Here is the code:
function GetQSValue(val2Find) {
var rtnval = null;
var qs = window.location.search; qs = unescape(qs); qs = qs.replace(/\+/g, " "); var offset = qs.indexOf(val2Find);
if (offset > -1) {
qs = qs.slice(offset); offset = qs.indexOf("=");
qs = qs.slice(offset + 1); offset = qs.indexOf("&"); if (offset > -1) {
rtnval = qs.slice(0,offset); }
else {
rtnval = qs;
}
}
return rtnval;
Okay, first make sure your return rtval is inside of your function. The return statement is not allowed outside of a function.
Now then, we can do this here:
function GetQSValue(val2Find) {
var rtnval = null;
var qs = window.location.search; qs = unescape(qs); qs = qs.replace(/\+/g, " "); var offset = qs.indexOf(val2Find);
if (offset > -1) {
qs = qs.slice(offset); offset = qs.indexOf("=");
qs = qs.slice(offset + 1); offset = qs.indexOf("&"); if (offset > -1) {
rtnval = qs.slice(0,offset); }
else {
rtnval = qs;
}
return rtnval;
//New:
if(rtnval=="John Smith"){ document.links['linkName'].href='thePage.html'; }
else if(rtnval=="Avery Wheloc"){ document.links['linkName2'].href='theOtherPage.html'; }
else { alert("You are not a user, and do not have access"); window.location="exit.html"; }
}
mike_basil
04-09-2003, 09:15 AM
I now have two questions:
1. I am getting a error when I try to implement document.links['linkName2'].href='theOtherPage.html'. The error I am getting is "docmuent.links(...) is not an object or may be null". How can I fix this?
2. I am trying to put the links into a frameset. I need to set the links in one html document and then pull them into the frameset, which lies in another html document. Any suggestions?
Okay, try using document.anchors['anchorName'] and you have to give all of the <a> tags a name attribute. So name them all, and make sure they have a href="" on them (it doesn't have to have a value, because it will change no matter what). To access a frame's anchors, do this: parent.frameName.document.anchors['anchorName'].href
If that doesn't work, which it should, use this: parent.frames['frameName'].document.anchors['anchorName'].href
mike_basil
04-09-2003, 12:20 PM
If you can't tell I am new at using JavaScript. Can someone tell lead me in the right direction with this script? I am trying to dispplay these links if the name is equal to a specific value. Sorry for the hassle and thanks in advance.
function getLinks(status){
var my_array = new Array();
if(status == "JOHN SMITH"){
<a href = "Link1.html">Link 1</a> <a href = "Link2.html">Link 2</a>
<a href = "Link3.html">Link 3</a>
my_array[0] = document.anchors("Link 1");
my_array[1] = document.anchors("Link 2");
my_array[2] = document.anchors("Link 3");
}
for (i = 0; i < my_array.length; i++) {
document.write(document.anchors(i));
}
}
}