Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. [SOLVED] Keep the page position? [modified]

[SOLVED] Keep the page position? [modified]

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
javascriptcomquestion
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Joan M

    Hello all, I'm trying to keep the page still... :rolleyes: without luck... In one of the pages I'm making I have a list of divs that are giving an effect of rows in a listctrl... you know one is gray, the next one white, the third gray again and so on... In each of those rows there is a link that allows me to show/hide a form that is at the bottom of each div (I'm using some code like this one[^]). If the complete page doesn't fit into the explorer window, each time that I press that link the page moves to the top giving the user a strange feeling as the user has to search again the content that needs in the page... How could I maintain it at the same position? Thank you in advance! :thumbsup:

    [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

    modified on Thursday, June 9, 2011 11:18 AM

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #3

    If it is a floating div, why not set the overflow parameter

    J 2 Replies Last reply
    0
    • A all_in_flames

      One simple solution to this problem would be to focus on an anchor (<a> tag) or one of the form fields that you're dynamically showing, e.g.:

      function focusOn(elementId) {
      getElementById(elementId).focus();
      }

      I assume this is required because the page must be reloaded when you're showing the form controls? A better solution may be to just have them on the page all the time, but using the

      display:none

      CSS style, and then set the one you want to be visible. Hope this helps! Cheers!

      J Offline
      J Offline
      Joan M
      wrote on last edited by
      #4

      Hello all_in_flames (I hope you are well :rolleyes:), I've tried the first option about the <a> tag... this semi-works as the page gets moved as before but a little bit better as it shows the content centered... Also tried to use focus()... without luck... it seems it don't work for me...

      function toggle(id)
      {
      var e = document.getElementById(id);
      if(e.style.display == 'block')
      {
      e.style.display = 'none';
      e.focus();
      }
      else
      {
      e.style.display = 'block';
      e.focus();
      }
      }

      then arriving at your last recommendation... I think it is how I'm doing it right now... I've put all the content there but the style is display:none and I "only" show and hide it... This has been my initial approach and the behavior is not what I want... Any idea on what should I do? Thank you in advance!

      [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

      A 1 Reply Last reply
      0
      • J Joan M

        Hello all_in_flames (I hope you are well :rolleyes:), I've tried the first option about the <a> tag... this semi-works as the page gets moved as before but a little bit better as it shows the content centered... Also tried to use focus()... without luck... it seems it don't work for me...

        function toggle(id)
        {
        var e = document.getElementById(id);
        if(e.style.display == 'block')
        {
        e.style.display = 'none';
        e.focus();
        }
        else
        {
        e.style.display = 'block';
        e.focus();
        }
        }

        then arriving at your last recommendation... I think it is how I'm doing it right now... I've put all the content there but the style is display:none and I "only" show and hide it... This has been my initial approach and the behavior is not what I want... Any idea on what should I do? Thank you in advance!

        [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

        A Offline
        A Offline
        all_in_flames
        wrote on last edited by
        #5

        There are only a small subset of HTML elements that can accept focus. I believe all of the input fields (text boxes, check and radio boxes, etc) and anchor tags are able to accept a focus() call. I would pass the id of an element that can be focused on as well as the id of the element to be shown/hidden:

        function toggle(toggleId, focusId)
        {
        var e = document.getElementById(toggleId);
        var f = document.getElementById(focusId);
        if(e.style.display == 'block')
        {
        e.style.display = 'none';
        f.focus();
        }
        else
        {
        e.style.display = 'block';
        f.focus();
        }
        }

        Good luck!

        J 2 Replies Last reply
        0
        • L Lost User

          If it is a floating div, why not set the overflow parameter

          J Offline
          J Offline
          Joan M
          wrote on last edited by
          #6

          It is not a floating div... Not at least if you are speaking about the "float" style. Anyway I've searched for the overflow parameter and I've seen that it is used to show scrollbars... :~ Thank you for your feedback.

          [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

          1 Reply Last reply
          0
          • A all_in_flames

            There are only a small subset of HTML elements that can accept focus. I believe all of the input fields (text boxes, check and radio boxes, etc) and anchor tags are able to accept a focus() call. I would pass the id of an element that can be focused on as well as the id of the element to be shown/hidden:

            function toggle(toggleId, focusId)
            {
            var e = document.getElementById(toggleId);
            var f = document.getElementById(focusId);
            if(e.style.display == 'block')
            {
            e.style.display = 'none';
            f.focus();
            }
            else
            {
            e.style.display = 'block';
            f.focus();
            }
            }

            Good luck!

            J Offline
            J Offline
            Joan M
            wrote on last edited by
            #7

            X| OK, now I've put the focus on the first editbox in the form... I'm seeing another problem here... and I think I'm trying to solve it in the wrong way: In order to allow the user to click somewhere to toggle the form on/off I've put a link. That link links to # (href="#") this seems to be the cause of my problems as if I remove that (href="#") then the page doesn't moves. The only problem here is that it also shows the link as plain text (black + no hovering effects) so the user won't notice it as a link... How would you proceed in that case? Thank you for your time! :thumbsup:

            [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

            1 Reply Last reply
            0
            • J Joan M

              Hello all, I'm trying to keep the page still... :rolleyes: without luck... In one of the pages I'm making I have a list of divs that are giving an effect of rows in a listctrl... you know one is gray, the next one white, the third gray again and so on... In each of those rows there is a link that allows me to show/hide a form that is at the bottom of each div (I'm using some code like this one[^]). If the complete page doesn't fit into the explorer window, each time that I press that link the page moves to the top giving the user a strange feeling as the user has to search again the content that needs in the page... How could I maintain it at the same position? Thank you in advance! :thumbsup:

              [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

              modified on Thursday, June 9, 2011 11:18 AM

              G Offline
              G Offline
              Graham Breach
              wrote on last edited by
              #8

              Make sure that your click handler returns false:

              <a href="#" onclick="function();return false">Link</a>

              or

              <a href="#" onclick="return function();">Link</a>

              if function() returns false.

              J 1 Reply Last reply
              0
              • A all_in_flames

                There are only a small subset of HTML elements that can accept focus. I believe all of the input fields (text boxes, check and radio boxes, etc) and anchor tags are able to accept a focus() call. I would pass the id of an element that can be focused on as well as the id of the element to be shown/hidden:

                function toggle(toggleId, focusId)
                {
                var e = document.getElementById(toggleId);
                var f = document.getElementById(focusId);
                if(e.style.display == 'block')
                {
                e.style.display = 'none';
                f.focus();
                }
                else
                {
                e.style.display = 'block';
                f.focus();
                }
                }

                Good luck!

                J Offline
                J Offline
                Joan M
                wrote on last edited by
                #9

                Already solved... Nice suggestion to use focus on the desired control, but it did not make it... Anyway returning false after the function worked... See Graham Breach[^] answer[^]. Thank you again for your time and feedback!

                [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                1 Reply Last reply
                0
                • L Lost User

                  If it is a floating div, why not set the overflow parameter

                  J Offline
                  J Offline
                  Joan M
                  wrote on last edited by
                  #10

                  Already solved Richard, Graham Breach[^] has saved me! :-D The way to do it was to return a false... See his answer[^]. thank you for your time and help! :thumbsup:

                  [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                  1 Reply Last reply
                  0
                  • G Graham Breach

                    Make sure that your click handler returns false:

                    <a href="#" onclick="function();return false">Link</a>

                    or

                    <a href="#" onclick="return function();">Link</a>

                    if function() returns false.

                    J Offline
                    J Offline
                    Joan M
                    wrote on last edited by
                    #11

                    Definitely Graham... there should be a button with more "o" as in "Goooo...oooood answer". This was one of those things that can't be searched in the internet (not at least with my google-fu). a big THANK YOU! :thumbsup:

                    [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                    G 1 Reply Last reply
                    0
                    • J Joan M

                      Definitely Graham... there should be a button with more "o" as in "Goooo...oooood answer". This was one of those things that can't be searched in the internet (not at least with my google-fu). a big THANK YOU! :thumbsup:

                      [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                      G Offline
                      G Offline
                      Graham Breach
                      wrote on last edited by
                      #12

                      I know what you mean - without already knowing the answer, I wouldn't know what to search for either. Here's quite an interesting page I found about it: http://www.quirksmode.org/js/events_early.html[^]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups