|
示例
1
:
获取文档显示区域的高度和宽度
示例
2
:
获取外部窗体的宽度和高度
示例
3
:
打开一个新的窗口
示例
1
:
获取文档显示区域的高度和宽度
顶
折
一旦页面加载,就会自动创建window对象,所以无需手动创建window对象。 通过window对象可以获取文档显示区域的高度和宽度
");
window.frames["iframe_show1156"].document.write(decodeHtml($("textarea#stepcodeTextarea1156").val()));
window.frames["iframe_show1156"].document.close();
$(window.frames["iframe_show1156"]).load(function(){
$("#iframe_show1156").height($("#iframe_show1156").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1156").height($("#iframe_show1156").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
document.write("文档内容");
document.write("文档显示区域的宽度"+window.innerWidth);
document.write("<br>");
document.write("文档显示区域的高度"+window.innerHeight);
</script>
<script>
document.write("文档内容");
document.write("文档显示区域的宽度"+window.innerWidth);
document.write("<br>");
document.write("文档显示区域的高度"+window.innerHeight);
</script>
");
window.frames["iframe1156"].document.write(decodeHtml(code1156));
window.frames["iframe1156"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1156"]).load(function(){
$("#iframe1156").height($("#iframe1156").contents().find("body").height()+showittryitheight);
});
$("#iframe1156").height($("#iframe1156").contents().find("body").height()+showittryitheight);
alreadyWriteCode1156 = code1156;
$("#rendering1156").hide();
$("#rendered1156").show();
}
var tRereshRetry2DemoPanel1156 = setInterval(rereshRetry2DemoPanel1156,1000);
var binded1156 = false;
$("textarea#stepcodeTextarea1156").keyup(function(){
if(!binded1156){
$(window).bind('beforeunload',function(){
binded1156 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1156 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1156!=newCode){
// window.frames["iframe1156"].document.write("
");
// window.frames["iframe1156"].document.write(decodeHtml($("textarea#stepcodeTextarea1156").val()));
// window.frames["iframe1156"].document.close();
// $(window.frames["iframe1156"]).load(function(){
// $("#iframe1156").height($("#iframe1156").contents().find("body").height()+showittryitheight);
// });
// code1156 = newCode;
// }
});
$(".tryButton1156").click(function(){
$("#tryDiv1156").show();
$("#stepcodeTextarea1156").focus();
$("#stepcodeTextarea1156").height(200);
$("#iframe1156").height(0);
window.frames["iframe1156"].document.write("
");
window.frames["iframe1156"].document.write(decodeHtml($("textarea#stepcodeTextarea1156").val()));
window.frames["iframe1156"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1156"]).load(function(){
$("#iframe1156").height($("#iframe1156").contents().find("body").height()+showittryitheight);
});
$("#iframe1156").height($("#iframe1156").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1156.focus();
editor1156.setSize(null, "250");
$("#rendering1156").hide();
$("#rendered1156").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor1156 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1156"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor1156.on("change",function(doc){
if(!binded1156){
$(window).bind('beforeunload',function(){
binded1156 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1156 = newCode;
$("textarea#stepcodeTextarea1156").val(newCode);
if(alreadyWriteCode1156!=code1156){
lastModifedTime1156 = new Date().getTime();
$("#rendering1156").show();
$("#rendered1156").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1156 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1156.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1156").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
所谓的外部窗体即浏览器,可能用的是360,火狐,IE, Chrome等等。
");
window.frames["iframe_show1157"].document.write(decodeHtml($("textarea#stepcodeTextarea1157").val()));
window.frames["iframe_show1157"].document.close();
$(window.frames["iframe_show1157"]).load(function(){
$("#iframe_show1157").height($("#iframe_show1157").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1157").height($("#iframe_show1157").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
document.write("浏览器的宽度:"+window.outerWidth);
document.write("<br>");
document.write("浏览器的高度:"+window.outerHeight);
</script>
<script>
document.write("浏览器的宽度:"+window.outerWidth);
document.write("<br>");
document.write("浏览器的高度:"+window.outerHeight);
</script>
");
window.frames["iframe1157"].document.write(decodeHtml(code1157));
window.frames["iframe1157"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1157"]).load(function(){
$("#iframe1157").height($("#iframe1157").contents().find("body").height()+showittryitheight);
});
$("#iframe1157").height($("#iframe1157").contents().find("body").height()+showittryitheight);
alreadyWriteCode1157 = code1157;
$("#rendering1157").hide();
$("#rendered1157").show();
}
var tRereshRetry2DemoPanel1157 = setInterval(rereshRetry2DemoPanel1157,1000);
var binded1157 = false;
$("textarea#stepcodeTextarea1157").keyup(function(){
if(!binded1157){
$(window).bind('beforeunload',function(){
binded1157 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1157 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1157!=newCode){
// window.frames["iframe1157"].document.write("
");
// window.frames["iframe1157"].document.write(decodeHtml($("textarea#stepcodeTextarea1157").val()));
// window.frames["iframe1157"].document.close();
// $(window.frames["iframe1157"]).load(function(){
// $("#iframe1157").height($("#iframe1157").contents().find("body").height()+showittryitheight);
// });
// code1157 = newCode;
// }
});
$(".tryButton1157").click(function(){
$("#tryDiv1157").show();
$("#stepcodeTextarea1157").focus();
$("#stepcodeTextarea1157").height(200);
$("#iframe1157").height(0);
window.frames["iframe1157"].document.write("
");
window.frames["iframe1157"].document.write(decodeHtml($("textarea#stepcodeTextarea1157").val()));
window.frames["iframe1157"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1157"]).load(function(){
$("#iframe1157").height($("#iframe1157").contents().find("body").height()+showittryitheight);
});
$("#iframe1157").height($("#iframe1157").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1157.focus();
editor1157.setSize(null, "250");
$("#rendering1157").hide();
$("#rendered1157").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor1157 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1157"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor1157.on("change",function(doc){
if(!binded1157){
$(window).bind('beforeunload',function(){
binded1157 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1157 = newCode;
$("textarea#stepcodeTextarea1157").val(newCode);
if(alreadyWriteCode1157!=code1157){
lastModifedTime1157 = new Date().getTime();
$("#rendering1157").show();
$("#rendered1157").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1157 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1157.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1157").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
有的时候,你碰到一些网站会自动打开另一个网站,那么是怎么做到的呢?
就是通过window的open方法做到的
不建议使用,如果需要打开一个新的网站,应该通过超级链接等方式让用户主动打开,在没有告知用户的前提下就打开一个新的网站会影响用户的体验
");
window.frames["iframe_show1158"].document.write(decodeHtml($("textarea#stepcodeTextarea1158").val()));
window.frames["iframe_show1158"].document.close();
$(window.frames["iframe_show1158"]).load(function(){
$("#iframe_show1158").height($("#iframe_show1158").contents().find("body").height()+showittryitheight);
});
$("#iframe_show1158").height($("#iframe_show1158").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script>
function openNewWindow(){
myWindow=window.open("/");
}
</script>
<button onclick="openNewWindow()">打开一个新的窗口</button>
<script>
function openNewWindow(){
myWindow=window.open("/");
}
</script>
<button onclick="openNewWindow()">打开一个新的窗口</button>
");
window.frames["iframe1158"].document.write(decodeHtml(code1158));
window.frames["iframe1158"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1158"]).load(function(){
$("#iframe1158").height($("#iframe1158").contents().find("body").height()+showittryitheight);
});
$("#iframe1158").height($("#iframe1158").contents().find("body").height()+showittryitheight);
alreadyWriteCode1158 = code1158;
$("#rendering1158").hide();
$("#rendered1158").show();
}
var tRereshRetry2DemoPanel1158 = setInterval(rereshRetry2DemoPanel1158,1000);
var binded1158 = false;
$("textarea#stepcodeTextarea1158").keyup(function(){
if(!binded1158){
$(window).bind('beforeunload',function(){
binded1158 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code1158 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code1158!=newCode){
// window.frames["iframe1158"].document.write("
");
// window.frames["iframe1158"].document.write(decodeHtml($("textarea#stepcodeTextarea1158").val()));
// window.frames["iframe1158"].document.close();
// $(window.frames["iframe1158"]).load(function(){
// $("#iframe1158").height($("#iframe1158").contents().find("body").height()+showittryitheight);
// });
// code1158 = newCode;
// }
});
$(".tryButton1158").click(function(){
$("#tryDiv1158").show();
$("#stepcodeTextarea1158").focus();
$("#stepcodeTextarea1158").height(200);
$("#iframe1158").height(0);
window.frames["iframe1158"].document.write("
");
window.frames["iframe1158"].document.write(decodeHtml($("textarea#stepcodeTextarea1158").val()));
window.frames["iframe1158"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe1158"]).load(function(){
$("#iframe1158").height($("#iframe1158").contents().find("body").height()+showittryitheight);
});
$("#iframe1158").height($("#iframe1158").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor1158.focus();
editor1158.setSize(null, "250");
$("#rendering1158").hide();
$("#rendered1158").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor1158 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea1158"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor1158.on("change",function(doc){
if(!binded1158){
$(window).bind('beforeunload',function(){
binded1158 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code1158 = newCode;
$("textarea#stepcodeTextarea1158").val(newCode);
if(alreadyWriteCode1158!=code1158){
lastModifedTime1158 = new Date().getTime();
$("#rendering1158").show();
$("#rendered1158").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor1158 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor1158.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv1158").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|