Results 1 to 2 of 2

Thread: return to the same place instead of anchors

  1. #1
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default return to the same place instead of anchors

    Hi!
    I have a page that is being updated every few minutes and I want that in every load the page would return to the same place it was before.
    right now I'm using anchors (#)- but it is not specific enough and pretty annoying.

    I would appreciate your help!

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    play with

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    /*<![CDATA[*/
    
    #splash {
      position:relative;z-Index:190;width:400px;background-Color:#FFCC66;padding:10px;border:solid red 1px;
    }
    
    
    /*]]>*/
    </style></head>
    
    <body>
    <div style="height:800px;" ></div>
    <div id="splash" ></div>
    <div style="height:400px;" ></div>
    <input type="button" name="" value="Load Content" onmouseup="zxcTest('splash','ajax.htm')" />
    <div style="height:800px;" ></div>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function zxcTest(id,a){
     var obj=document.getElementById(id);
     if (obj&&typeof(a)=='string'){
      var o={obj:obj,a:document.createElement('A')};
      document.body.appendChild(o.a);
      o.os=o.a.offsetTop;
      Ajax(o,a);
     }
    }
    
    function wwhs(){
      return window.innerHeight?window.pageYOffset:document.documentElement.clientHeight?document.documentElement.scrollTop:document.body.scrollTop;
     }
    
    function pos(obj){
      var rtn=[0,0];
      while(obj){
       rtn[0]+=obj.offsetLeft;
       rtn[1]+=obj.offsetTop;
       obj=obj.offsetParent;
      }
      return rtn;
     }
    
    // Optional AJAX Code.
    function Ajax(o,url){
      var oop=this,html=false;
      if (window.ActiveXObject){
       try {
        html=new ActiveXObject("Msxml2.XMLHTTP");
       }
       catch (e){
        try {
         html=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e){
        }
       }
      }
      else if (window.XMLHttpRequest){
       html=new XMLHttpRequest();
      }
      else {
       return false;
      }
      html.onreadystatechange=function(){ ajaxpopulate(o,html); }
      html.open('GET',url+'?'+new Date().getTime(),true);
      try {
       html.send(null);
      }
      catch (e){
      }
     }
    
    function ajaxpopulate(o,html){
      if (html.readyState==4&&(html.status==200||window.location.href.indexOf("http")==-1)){
       o.obj.innerHTML=html.responseText;
       if (wwhs()>pos(o.obj)[1]+o.obj.offsetHeight){  //
        window.scrollTo(0,wwhs()+o.a.offsetTop-o.os);
       }
      }
     }
    
    
    
    /*]]>*/
    </script>
    </body>
    
    </html>
    ajax.htm

    Code:
      The script allows elements defined in the  page HTML and assigned an ID name or AJAX file<br />
      to be viewed as a Pop Up or Tool Tip.<br />
      With nine modes of opening the Pop Up including seven clip modes, fade and random clip,<br />
        &nbsp;&nbsp;'C' = center clip,<br />
        &nbsp;&nbsp;'H' = horizontal clip,<br />
        &nbsp;&nbsp;'V' = vertical clip,<br />
        &nbsp;&nbsp;'R' = right clip,<br />
        &nbsp;&nbsp;'L' = left clip,<br />
        &nbsp;&nbsp;'D' = down clip,<br />
        &nbsp;&nbsp;'U' = up clip,<br />
        &nbsp;&nbsp;'F' = fade,<br />
        &nbsp;&nbsp;'I' = instant,<br />
        &nbsp;&nbsp;'?' = Random Clip<br />
      The Pop Up may be viewed offset from the link activating the Pop Up<br />
      or in the center of the page on top of an optional 'mask' covering the rest of the page content.<br />
      The Pop Up may be displayed and hidden by click or mouseover of the link element or inline event calls.<br />
      <br />
      Optional 'Cookie' code allows a Pop Up to be displayed on initialization, allways, once every n days or browser session.
      <br />
      <br />
      This Pop Up will close after 15 seconds<br />
      or Click outside the Pop Up to Close.
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Similar Threads

  1. Help with anchors into current view.
    By sergiozambrano in forum JavaScript
    Replies: 1
    Last Post: 06-22-2009, 04:32 PM
  2. Anchors on the fly in IE
    By jsGreenhorn in forum JavaScript
    Replies: 1
    Last Post: 10-30-2008, 06:26 PM
  3. achive anchors
    By sir_yunus in forum JavaScript
    Replies: 4
    Last Post: 03-10-2008, 07:33 AM
  4. anchors href
    By sir_yunus in forum JavaScript
    Replies: 2
    Last Post: 03-08-2008, 04:51 PM
  5. I need help with my Anchors
    By JohnHow in forum Dynamic Drive scripts help
    Replies: 18
    Last Post: 09-01-2006, 07:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •