javascript 得到当前页面可视高度和宽度
function getHeight(){
var yScroll;
if (window.innerHeight && window.scrollMaxY) {
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
yScroll = document.body.offsetHeight;
}
var windowHeight;
if (self.innerHeight) { // all except Explorer
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) {
// Explorer 6 Strict Mode
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
return pageHeight;
}
function getWidth(){
var xScroll
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all b
相关文档:
javascript中replace()
在javascript中,String的函数replace()简直太让人喜爱了。它灵活而强大的字符替换处理能力,让我不禁想向大家介绍它。
replace()最简单的算是能力就是简单的字符替换。示例代码如下:
<script language="javascript">
var strM = "javascript is a good script ......
1>工厂函数来创建对象(Factory)
function createCar(){
var obj = new Object;
obj.name = "BWM";
obj.show = function(){
alert(this.name);
}
return obj;
}
var car1 = createCar();
var car2 = createCar();
car1.show();
car2.show();
2>构造函数创建对象 ......
indexOf
返回元素在数组的索引,没有则返回-1。与string的indexOf方法差不多。
如果其他浏览器没有实现此方法,可以用以下代码实现兼容:
Array.prototype.indexOf = function(el, start) {
var start = start || 0;
for ( var i=0; i < this.length; ++i ) {
......
"These memory leaks often
occur as a result of circular references between JavaScript objects and
objects within IE’s DOM (document object model)."
GPDE Team Blog
明显的DOM对象与 JavaScript对象循环引用很好判断,难的是隐含的循环引用判断!
隐含的循环引用需要通过作用域链进行分析判 ......