简体   繁体   中英

Load page in div, go to top of that div

I have:

<script language="javascript"> 
function arata(temp) { 
            var req = new XMLHttpRequest(); 
            req.open("GET", temp, false); 
            req.send(null); 
            var page = req.responseText; 
            document.getElementById("produs").innerHTML = page; 
                      } 
</script>

and:

<a href="#produs" onclick="arata('facturaies_vezi.php?nrfacties=<?=$row[nrfacties];?>#produs'); return true;"  id="<?=$nrcrt;?>">See details</a>

and:

<div id="produs"></div>

So, when the link is clicked, the page loads in to div.

How can I do to align the top of div to the top of the viewpoint? I mean... something like using an #anchor.

Try:

document.getElementById('produs').scrollIntoView();

See here for more info:

https://developer.mozilla.org/en/DOM/element.scrollIntoView

如果要使用锚,可以在div上方添加一个<a name="produs"></a> ,并且如果您在click事件上未return false ,则它应该可以工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM