今天js中使用document输出信息时,总是有进度条,在网上找到了这篇文章,很有帮助
原来的代码:
<html>
<body>
<script>
var h =
‘<html><body>aaaaaaaaaaaa</body></html>’;
//注意这里
document.write();方法对字符串“<script>””</script>””</html>””</body>”极可能出现匹配或过滤错误,导致输出不正常,最好转义一下。
h = h.replace("</","</");
function a ()
{
document.write(h);
return false;
}
</script>
<input type="button" onclick ="a()" value = "Try me"/>
</body>
</html>在firefox下,显示正常,但是进度条总显示正在加载。
后来发现是我忘了关闭document;
写到当前的文档:
<html> <head> <title>write example</title> <script type="text/javascript"> function newContent() { alert("load new content"); document.open(); document.write("<h1>Out with the old - in with the new!</h1>"); document.close(); } </script> </head> <body onload="newContent();"> <p>Some original document content.</p> </body> </html>写的新打开的文档,或者 iframe
<html>
<head><title>Write to IFRAME </title>
</head>
<body>
<iframe width="50%" height="100" id="iframe1" src=""></iframe>
<script language="JavaScript">
<!–
var str = ‘Hello I am sending this to <b>IFRAME</b>’;
// NO IE
if (!document.all) {
var ifr1 = document.getElementById(‘iframe1′);
ifr1.contentWindow.document.open();
ifr1.contentWindow.document.write(str);
ifr1.contentWindow.document.close();
}
// IE
else {
document.frames[0].document.open();
document.frames[0].document.write(str);
document.frames[0].document.close();
}
//–>
</script>
</body>
</html>
这里还有个比较复杂的例子等等研究一下
<html>
<head><title>Write to IFRAME </title>
</head>
<body>
<script language="javascript">
var txt="";
function handleErr(msg,url,l)
{
txt="There was an error on this page.nn"
txt+="Error: " + msg + "n"
txt+="URL: " + url + "n"
txt+="Line: " + l + "nn"
txt+="Click OK to continue.nn"
alert(txt)
return true
}
onerror=handleErr
function loadExternal(url) {
var ifr1 = document.getElementById(‘srcFrame’);
if (ifr1) {
ifr1.contentWindow.document.location = url;
//window.frames['srcFrame'].location = url;
return false;
}
return true;
}
function GetInnerHTML () {
var str = null;
if (!document.all) {
var ifr1 = document.getElementById(‘srcFrame’);
str = ifr1.contentWindow.document.documentElement.innerHTML;
}
else {
str = window.frames['srcFrame'].document.body.innerHTML;
}return (str);
}
function displayExternal() {
var str = GetInnerHTML ();
if (!str) { alert (‘Could not read contents of source iframe’); return; }
if (!document.all) {
var ifr1 = document.getElementById(‘trgFrame’);
ifr1.contentWindow.document.open();
ifr1.contentWindow.document.write(str);
ifr1.contentWindow.document.close();
}
// IE
else {
window.frames['trgFrame'].document.body.innerHTML = str;
/*
ifr1.document.open();
ifr1.document.write(str);
ifr1.document.close();
*/
}
}
</script>
<br>SRC FRAME
<br><input type="button" value="Load Local Page" onclick="(loadExternal(‘file.htm’));">
<br><input type="button" value="Load Yahoo !" onclick="(loadExternal(‘http://www.yahoo.com’));">
<br><iframe width="50%" height="100" id="srcFrame" src=""></iframe>
<br>TRG FRAME
<br><input type="button" value="Update Target Page" onclick="displayExternal();">
<br><iframe width="50%" height="100" id="trgFrame" src=""></iframe>
<script language="JavaScript">
</script>
</body>
</html>
引文地址:http://www.chuan.shanghuo.net/wordpress/?p=165
相关推荐
饼状进度条,可以对饼图的尺寸大小、进度条颜色、环形背景颜色及文字颜色进行设置。 示例:document.body.appendChild(percentpie(300, 160, 3, 2, "#fff", "#ddd", "#f00"));
JS中关于document.all的详解
该文件包含用MFC开发的一个多线程使用"进度条"(Prograss)的实例。 每次点击按钮都可以生成带有进度条的对话框。每个对话框的进度条占用一个线程。 单击kill按钮,可以结束线程。 能解决进度条假死的现象。 原文链接...
js技术中document对象技术汇总及产用方法的使用,带有例子
页面转向的进度条 代码 <!--要完成此效果把如下代码加入到区域中--> <p><font color="#0000ff">; color: #FF0000; font-family: Arial; font-weight: bolder; border-style: none; padding: 0px"> <input ...
1:js定时器 1)window.setInterval(函数名称,时间);//间隔定时器(反复调用),时间的单位是毫秒 2)window.clearInterval(定时器的返回值);停止定时器 3)window.setTimeout(函数名称,时间)//延时定时器,...
dom4j的Document对象格式化后输出String
JavaScript中的document语句类型比较多,不容易记忆和理解,这是我在网上整理的JS中document用法小结
javascript document方法属性 web 开发必备
JavaScript的document方法汇总
jsDocument
js document对象 window对象
javascript的document对象
document.bgColor //设置页面背景色 document.fgColor //设置前景色(文本颜色) document.linkColor //未点击过的链接颜色 document.alinkColor //激活链接(焦点在此链接上)的颜色 document.vlinkColor //已点击过的...
javascript document 对象 用法
document 对象.html-javascript中DOM对象内容
关于js的document对象的详细说明 转载的呵呵
这是一款带索引按钮,左右箭头,进度条,播放暂停按钮的jQuery的焦点图图片切换特效。 JS代码 [removed] </ script> [removed] </ script> [removed] jQuery(document).ready...
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。 但是,这不是所有的区别。当你ctrl + F5 一个链接 http://yourhost.com/#fragment 打印 alert(document.URL ); 和 alert([removed...
document.write()在JavaScript中怎样JSP调用