网页源代码直接复制保存没有效果的原因:
①网页代码的head部分有引用别的文件,包括js以及css样式。如果你没有对应的文件。网页上的样式和一些js写出来的效果是没有的。你的问题应该就是这个原因造成的。
②网页的代码中有一些是要依靠相应的web服务才能展示出来的。你如果没有相应的web服务器。例如iis或者Apache或者tomcat。你是没法看到相应的页面应该有的效果的。
从一般的浏览器上只是下载了页面源代码和图片,缺少js和css文件而导致的排版错乱。
解决方法:
步骤1、下载一个火狐浏览器。
步骤2、打开哈佛官网首页。
步骤3、鼠标右击点击将页面另存为,下载完毕你会发现不止有一个源代码页面,还有一个文件夹,文件夹内就有你缺少的js和css文件。
下载完毕后直接打开下载下的那个HTML页面即可,切记不要移动下载下的文件和文件夹,如果你移动了文件或者文件夹的位置,有可能会导致源代码读取路径不正确而排版错乱。
使用步骤:1.安装gulp以及gulp-file-include(NodeJs上)
2.新建gulpfile.js,配置 gulp-file-include:
var gulp =require('gulp')//引入gulp
var fileinclude =require('gulp-file-include')//引入gulp-file-include
gulp.task('fileinclude', function() {
gulp.src('src/**.html') .pipe(fileinclude({//gulp.src中存放要编译的文件
prefix:'@@',
basepath:'@file'
})).pipe(gulp.dest('dist'))//gulp.dest中存放编译后的文件的存放地址
})
3.通过@@include('include/header.html')引用header.html
4.在命令行工具里,执行gulp fileinclude。执行完毕后,dist目录里就有相对应的html文件。
使用步骤:1.安装gulp-ejs(NodeJs上)
2.新建gulpfile.js,配置 gulp-file-include:
var gulp = require('gulp')//引入gulp
var ejs = require('gulp-ejs')//引入gulp-ejs
gulp.task('ejs', function() {
gulp.src('Views/Business/financeManage1.ejs')//gulp.src中存放要编译的文件
.pipe(ejs({},{ext: '.html'}))//设置生成的文件后缀名为html
.pipe(gulp.dest('Views/dist'))//gulp.dest中存放编译后的文件的存放地址
})
3.通过<%-include ../template.html %>引用template.html
4.在命令行工具里,执行gulp ejs。执行完毕后,dist目录里就有相对应的html文件。
1.将项目放于本地服务器如xampp下
2.<iframe src="../template.html" width="100%" onload="reinitIframeEND()"></iframe>
3.function reinitIframe(){
var iframe = document.getElementById("iframepage")
console.log(iframe)
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight
var height = Math.max(bHeight, dHeight)
iframe.height = height
}catch (ex){
console.log(ex)
}
}
var timer1 = window.setInterval("reinitIframe()", 500)//定时开始
function reinitIframeEND(){
var iframe = document.getElementById("iframepage")
console.log("3")
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight
var height = Math.max(bHeight, dHeight)
console.log(bHeight+":"+dHeight)
iframe.height = height
}catch (ex){
console.log(ex)
}
// 停止定时
window.clearInterval(timer1)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)