【发布时间】:2012-08-16 12:56:19
【问题描述】:
我有一个包含文档的 offline html 文件,我必须输出文本文件的内容(在我的例子中是源代码)。有没有办法仅使用客户端功能(HTML 本身或 JS)将此文件的内容包含到 html 页面?
索引.html
<html>
<head>
<style>
p.source_code
{
font-family:"Courier New"
}
</style>
</head>
<body>
<p>
Some content
</p>
<p class="source_code">
<!-- place for output content of file main.cpp -->
</p>
</body>
</html>
main.cpp
#include <stdio.h>
int main()
{
printf("Hello World");
}
我希望我的页面在浏览器中看起来像
Some content
#include <stdio.h>
int main()
{
printf("Hello World");
}
【问题讨论】:
-
我不知道没有某种脚本可以做到这一点。
-
这是不可能的。框架是一种可能性,但可能会产生令人讨厌的副作用。
-
@shambulator: 闪烁,滚动尴尬等,就像在窗外看页面一样,你可以尝试让它尽可能无缝,但这并不容易。
-
很容易避开其中的一些
<iframe width=100% scrolling=no frameborder=no src="main.cpp" style="border: 0;" seamless>