PDA

View Full Version : return to the same place instead of anchors



d-machine
02-25-2014, 12:32 PM
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!

vwphillips
02-25-2014, 02:16 PM
play with


<!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


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.