Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2012, 04:48 AM   PM User | #1
Blinkin_Blippy
New to the CF scene

 
Join Date: Nov 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Blinkin_Blippy is an unknown quantity at this point
Question How to block some urls from being accessed, and allow others based on conditions.

I'm new to the forum, and hopefully I did a good job with the title.

I'm trying to create a script that will block people from viewing certain pages of a site if they have not uploaded a photo. I don't have server side scripting access, so I'm limited to what can be done, and need to use Javascript.

Essentially I want to block all urls except for a handful. When a person reaches a blocked page, I want to redirect them to the photo upload page.

The way that I find out if they have uploaded a photo is by this: $member_profile_image. That is a snippet the the platform gives that will display the url in text on the webpage. It doesn't require anything other than what I've given to do that, so the <?php reference to it in the script isn't needed, nor will it work because I don't have access to php.

What I've been trying to do thus far is finding out the indexOf a particular word in the default photo's address on the server. Default meaning, if you haven't uploaded a photo, you have the default one that everyone does when they first join. The address for the photo contains the word "Default", and it indexes out at 22.

So, if the index value shows up at 22, and they are on a blocked page, redirect them to the photo upload page and alert("you have to upload a photo"). If the index value shows up at 22 and they are not on a blocked page, do nothing at all. What seems the easiest since I want pretty much all urls to blocked aside from a handful, would be to just say, if these urls and index of 22, do nothing, else redirect and alert.

What I'm working with is below, but it's total fail and I don't know why:

Code:
image = "$member_profile_image"; // Displays the url as text, no <?php.
upload = image.indexOf("Default") === 22; // Default indexes at 22 in the url
myurls = [
          'http://www.myurl1.com',
          'http://www.myurl1.com/wiki.htm',
          'http://www.myurl1.com/?page=login&cmd=confirm,
          'http://www.myurl1.com/blog.htm'
            ];
    if(myurls.indexOf(window.location) > -1 && upload)
        {
           //This is where I need the code to do nothing at all.
        }
       else{
              alert("you have to upload an image to access this page");
            window.location.replace("http://www.myurl1/member/?page=settings");
        }
I've tried it this way and I can't get much of anything to happen at all. Anyone have any advice or tip on what could be going wrong?

Last edited by Blinkin_Blippy; 11-09-2012 at 06:02 AM.. Reason: fixed code tag
Blinkin_Blippy is offline   Reply With Quote
Old 11-09-2012, 06:08 AM   PM User | #2
Blinkin_Blippy
New to the CF scene

 
Join Date: Nov 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Blinkin_Blippy is an unknown quantity at this point
I'm not sure where my topic content went, or if I'm doing something wrong, but here it is again. I'm not able to see it anymore for some reason.

@Mods, my apologies for the double posting of this topic, and please remove the other one that is identical.

I'm new to the forum, and hopefully I did a good job with the title.

I'm trying to create a script that will block people from viewing certain pages of a site if they have not uploaded a photo. I don't have server side scripting access, so I'm limited to what can be done, and need to use Javascript.

Essentially I want to block all urls except for a handful. When a person reaches a blocked page, I want to redirect them to the photo upload page.

The way that I find out if they have uploaded a photo is by this: $member_profile_image. That is a snippet the the platform gives that will display the url in text on the webpage. It doesn't require anything other than what I've given to do that, so the <?php reference to it in the script isn't needed, nor will it work because I don't have access to php.

What I've been trying to do thus far is finding out the indexOf a particular word in the default photo's address on the server. Default meaning, if you haven't uploaded a photo, you have the default one that everyone does when they first join. The address for the photo contains the word "Default", and it indexes out at 22.

So, if the index value shows up at 22, and they are on a blocked page, redirect them to the photo upload page and alert("you have to upload a photo"). If the index value shows up at 22 and they are not on a blocked page, do nothing at all. What seems the easiest since I want pretty much all urls to blocked aside from a handful, would be to just say, if these urls and index of 22, do nothing, else redirect and alert.

What I'm working with is below, but it's total fail and I don't know why:

[CODE]
image = "$member_profile_image"; // Displays the url as text, no <?php.
upload = image.indexOf("Default") === 22; // Default indexes at 22 in the url
myurls = [
'http://www.myurl1.com',
'http://www.myurl1.com/wiki.htm',
'http://www.myurl1.com/?page=login&cmd=confirm,
'http://www.myurl1.com/blog.htm'
];
if(myurls.indexOf(window.location) > -1 && upload)
{
//This is where I need the code to do nothing at all.
}
else{
alert("you have to upload an image to access this page");
window.location.replace("http://www.myurl1/member/?page=settings");
}
[CODE]

I've tried it this way and I can't get much of anything to happen at all. Anyone have any advice or tip on what could be going wrong?
Blinkin_Blippy is offline   Reply With Quote
Old 11-09-2012, 07:17 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
In what way does it not work?

In this code:
Code:
if(myurls.indexOf(window.location) > -1 && upload) 
{ 
    //This is where I need the code to do nothing at all. 
}
Your comment *IS* "nothing at all", so indeed if it reached that point it will do nothing at all.

But you need to be more speciific about what and how it doesn't work.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-09-2012, 01:37 PM   PM User | #4
Blinkin_Blippy
New to the CF scene

 
Join Date: Nov 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Blinkin_Blippy is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
In what way does it not work?

In this code:
Code:
if(myurls.indexOf(window.location) > -1 && upload) 
{ 
    //This is where I need the code to do nothing at all. 
}
Your comment *IS* "nothing at all", so indeed if it reached that point it will do nothing at all.

But you need to be more speciific about what and how it doesn't work.
It doesn't block the urls I have listed, and indeed does do nothing, but it also does nothing on any of the pages that I don't have listed as well. So the else statement doesn't seem to be working at all.

I've also tried to test each aspect of the code, as in before the else statement.

Code:
image = "$member_profile_image"; 
  upload= image.indexOf("Default") = "22";
 myurls = [ 
 'http://www.websiteforyou.spruz.com', 'http://www.websiteforyou.spruz.com/wiki.htm', 'http://www.websiteforyou.spruz.com/?page=login&cmd=confirm, 'http://www.websiteforyou.spruz.com/blog.htm' ]; if(myurls.indexOf(window.location) > -1 && upload) {
alert("something");
}
I'm unable to figure out why that isn't firing at all. I go to those pages, and no alert box pops up.
Blinkin_Blippy is offline   Reply With Quote
Old 11-09-2012, 09:05 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Well, you have two choices:

(1) Learn to use a JavaScript debugger. I like the one in Chrome best, but the one in MSIE 9 is almost identical (just a tad harder to read) and FireBug for FireFox is fine as well. In the long run this is far far and away the better choice. It will save you dozens of hours of asking other people what is wrong with your code when 30 seconds in the debugger will point it out to you.

(2) Post a link to your actual page so we can use a debugger on it.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Blinkin_Blippy (11-09-2012)
Old 11-09-2012, 11:30 PM   PM User | #6
Blinkin_Blippy
New to the CF scene

 
Join Date: Nov 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Blinkin_Blippy is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Well, you have two choices:

(1) Learn to use a JavaScript debugger. I like the one in Chrome best, but the one in MSIE 9 is almost identical (just a tad harder to read) and FireBug for FireFox is fine as well. In the long run this is far far and away the better choice. It will save you dozens of hours of asking other people what is wrong with your code when 30 seconds in the debugger will point it out to you.

(2) Post a link to your actual page so we can use a debugger on it.
I'm thankful you mentioned the debugger. I don't have the foggiest idea how to use one, and would probably be best enlightened with a link of a good tutorial for it instead, so I can take some self help procedures, rather than temporary enlightenment.

What we be the easiest way to educate myself on using the debugger?
Blinkin_Blippy is offline   Reply With Quote
Old 11-09-2012, 11:57 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
https://developer.chrome.com/extensi...debugging.html

That assumes you will use Chrome. I would; it's not a LOT different than the other debuggers, but it's just enough different to be a little more "friendly".
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Blinkin_Blippy (11-10-2012)
Old 11-10-2012, 12:59 AM   PM User | #8
Blinkin_Blippy
New to the CF scene

 
Join Date: Nov 2012
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Blinkin_Blippy is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
https://developer.chrome.com/extensi...debugging.html

That assumes you will use Chrome. I would; it's not a LOT different than the other debuggers, but it's just enough different to be a little more "friendly".
Thank you. After learning css and Html, I definitely use chrome or firefox. I soooo hate IE, and look forward to it's demise lol.
Blinkin_Blippy is offline   Reply With Quote
Reply

Bookmarks

Tags
allow urls, block urls, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:00 PM.


Advertisement
Log in to turn off these ads.