Jquery

scroll div to bottom  on page load 

$(document).ready(function(){
var $t = $(‘#chat_viewport’);
$t.animate({“scrollTop”: $(‘#chat_viewport’)[0].scrollHeight}, “slow”);
});

 

 

 

 


scroll div top to bottom and bottom to top

$(function () {
var height = 0;
function scroll(height, ele) {
this.stop().animate({ scrollTop: height }, 1000, function () {
var dir = height ? “top” : “bottom”;
$(ele).html(“scroll to “+ dir).attr({ id: dir });
});
};
var wtf = $(‘#scroll’);
$(“#bottom, #top”).click(function () {
height = height < wtf[0].scrollHeight ? wtf[0].scrollHeight : 0;
scroll.call(wtf, height, this);
});
});

https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
<span id=”bottom”>scroll to bottom</span>
<br />
<br />
<br />


leave this page or stay popup on close tab using JQUERY——

window.onbeforeunload = function (e) {
e = e || window.event;
e.returnValue = ‘You want to leave ? ‘;
};