Web Analytics Made Easy -
StatCounter "I'm a newbie...be gentle" - CodingForum

Announcement

Collapse
No announcement yet.

"I'm a newbie...be gentle"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • "I'm a newbie...be gentle"

    Alrighty,

    I have a big question for anyone who thinks they might be able to tackle it.

    Is it possible to create a javascript for html that will close the window unless their history shows that they came from a specific page?

    I'll explain further. I have a password page, call it password.html. I also have the protected page, call it protected.html. I have a Macromedia Flash password gate on my password.html page to get to protected.html. This is because my server does not allow a .htaccess folder (it's cheap) so I found a way around that. Unfortunately, people using a public computer leave protected.html in the history, which anyone can click on and visit. I want to find a way to make it so that only someone coming from password.html can see that page. I guess the script would be something like what follows:

    if history:javascript back 1=password.html
    do nothing
    else
    document.write=access denied
    window.self.close


    Of course, I know nothing about writing javascript language, so what I just said might be like swearing in sign language without realizing it. :P Thanks for your patience and time.

    -Javawhat

  • #2
    Well... Let's see, it might be some solutions, I though at:

    insert your protected.html in an iframe on password.html. In fact open it in an iframe only if password application is passed.

    If so, you may use a small javascript code to verify if the page protected was open within that iframe. If not, self close or redirect to password.html

    try this in head of protected.html

    <script>
    function redir(){
    if(parent.frames.length==0){
    self.close();
    }
    }
    </script>

    or

    <script>
    function redir(){
    if(parent.frames.length==0){
    window.location="password.html";
    }
    }
    </script>

    Anyway, if user has javascript disabled, that code is usless... A server-side application would be safer.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    Comment


    • #3
      ...aaa... of course, call the function on onload...


      <script>
      function redir(){
      if(parent.frames.length==0){
      self.close();
      }
      }
      window.onload=redir;
      </script>

      or

      <script>
      function redir(){
      if(parent.frames.length==0){
      window.location="password.html";
      }
      }
      window.onload=redir;

      </script>
      KOR
      Offshore programming
      -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

      Comment


      • #4
        YES!

        Wow. Absolutely wow. You are a genius! Someone give this person an award! Thank you so very very much!!! You have made life good again!

        Comment


        • #5
          Ummm... Try taking a look at the posting guidlines ... The subject should SOMEHOW relate to the question... Sorry for being a nagger...



          digicm
          ?


          digicam

          Comment


          • #6
            Someone give this person an award
            Unofficialy one says that Romanians are the second best web programmers after the Indians... Thanks for appreciation.

            I try to find a similar solution if pages are open one from within other using window.onload() function (separate page, not frames or iframes). If finding a solution I might send it to you, either.

            ..Try taking a look at the ...
            I don't get it... Have I done something wrong, digicam??
            KOR
            Offshore programming
            -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

            Comment


            • #7
              No, "I'm a newbie...be gentle" is the title for this thread, which doesnt describe the problem.

              Funny enough, "I'm a newbie...be gentle" is one of the exact titles in the posting guidelines that it says would be a bad choice , but everyone makes mistakes, so javawhat, if you read through the posting guidlines (there isnt much there) and then your next topic title can have a better formulated name.
              PHP Weekly - A PHP Developers Resource
              PHP 5.1.4 and Ruby on Rails web hosting
              Moderator of PHP and Work offers and Requests
              Install Apache/PHP/MySQL
              (by marek_mar) | TinyPlugin Architecture

              Comment


              • #8
                lol Yes it is one of the exact titles. But Im sure he did it because he wanted the people to be curious... and read it! But still... Next time take a look at them.
                Thanks



                digicm
                ?


                digicam

                Comment


                • #9
                  alternative solution

                  You don't have to close the browser, you can just redirect to the password page. If the window that opened the protected page is on a parent window (not spawned window), the prompt to close the window is displayed, thus the user can choose to not close the window.
                  Now, here's the alternative solution using the referrer property which indicates what page the user came from.

                  <head>
                  <script type="text/javascript">
                  if (document.referrer!="http://www.mydomain/password.html")
                  location.href = "http://www.mydomain/password.html";
                  </script>
                  </head>

                  Of course, client-side protection is not the best solution. The user can just disable javascript and access the page. The best solution is to use server-side language.
                  Glenn
                  vBulletin Mods That Rock!

                  Comment


                  • #10
                    page contains iFrame

                    <script>
                    function redir(){
                    if(parent.frames.length==0){
                    window.location="password.html";
                    }
                    }
                    window.onload=redir;

                    </script>

                    Ok, this works great, but with one problem. It won't work when there's an iFrame on the page. Is there any way to fix that?

                    Comment


                    • #11
                      Have you tried my suggestion?
                      Glenn
                      vBulletin Mods That Rock!

                      Comment


                      • #12
                        not working

                        Yes, I tried it and it doesn't work. Perhaps I'm doing something wrong, but I like the frames script anyway. So is there any way to make it work when there's an iFrame on the page?

                        Comment

                        Working...
                        X