动态包含文件 [英] Dynamic include files

查看:60
本文介绍了动态包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


是否可以在html中动态使用include。


希望下面的例子能说明我的意思我很想做。


提前致谢

Adam


< script language =" javascript" >

function checkFileToInclude(){

if(location.search =="?file1"){

return"< ! - #include file =''file1.html'' - >"

} else {

return"<! - #include file =''file2.html'' - >"

}

}

< / script>


< html>

..

..

< a href =" www.mydomain。 com / test?file1">包括文件1< / a>

< a href =" www.mydomain.com/test?file2">包含文件2< / a> < br $> b $ b ..

..

< td>

document.write(checkFileToInclude())

< / td>


..
..

..

< / html>

Hi All,

Is it possible to use includes dynamically in html.

Hopefully the following example will give an idea what I am rying to do.

Thanks in advance
Adam

<script language="javascript">
function checkFileToInclude(){
if (location.search == "?file1"){
return "<!--#include file=''file1.html''-->"
}else{
return "<!--#include file=''file2.html''-->"
}
}
</script>

<html>
..
..
<a href="www.mydomain.com/test?file1">Include File 1</a>
<a href="www.mydomain.com/test?file2">Include File 2</a>
..
..
<td>
document.write(checkFileToInclude())
</td>

..
..
..
</html>

推荐答案

Adam写道:
大家好,

是否有可能在html中动态使用include。

....

< script language =" javascript">
function checkFileToInclude(){
if(location.search =="?file1"){
return" < ;! - #include file =''file1.html'' - >"
} else {
return"<! - #include file =''file2.html '' - >"
}
}
< / script>
Hi All,

Is it possible to use includes dynamically in html.
....
<script language="javascript">
function checkFileToInclude(){
if (location.search == "?file1"){
return "<!--#include file=''file1.html''-->"
}else{
return "<!--#include file=''file2.html''-->"
}
}
</script>




除非此脚本在服务器...我假设您想要#b $ b执行#include语句中的操作,并且这些应该是在服务器端执行的,因为执行了JavaScript在

客户端,服务器永远不会知道什么过程。

有趣的是,这实际上可行,b然后是另一种方式

来自你的期望:服务器将*,*之前*结果发送给客户端,用内容替换SSI指令

* * * html文件和以后的JavaScript选择其中一个来使用

...


干杯,


Guido



Lol not unless this script runs on the server... I assume you want to
perform the actions in the #include statements, and those should be
performed on the server side, since the JavaScript is executed on the
client side the server will never know what process.
The funny thing is that this may actually work, but then the other way
round from what you seem to expect: the server will, *before* sending
the result to the client, replace the SSI instructions with the content
of *both* html files and later on the JavaScript picks one of those to
use...

Cheers,

Guido


文章< a8 ***************** *********@posting.google.com>,
ar ***** ***@hotmail.com 启发我们...
In article <a8**************************@posting.google.com >,
ar********@hotmail.com enlightened us with...
大家好,

是否可以在html中动态使用include。
Hi All,

Is it possible to use includes dynamically in html.




是的,但不是javascript,它在客户端上运行。 SSI在

服务器上运行。

你正在使用SSI作为包含 - 使用SSI来完成整个事情。你可以用
来检查查询字符串参数并有条件地包含内容。

http://www.carleton.ca/~dmcfet/html/ssi.html


- -

-

~kaeli~

用户:计算机专业人员使用时的意思

''白痴''。
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace



Yes, but not with javascript, which runs on the client. SSI runs on the
server.
You''re using SSI for the includes - use SSI for the whole thing. You can
use it to check a querystring param and conditionally include content.

http://www.carleton.ca/~dmcfet/html/ssi.html

--
--
~kaeli~
User: The word computer professionals use when they mean
''idiot''.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


Adam写道:
Adam wrote:
大家好,

是否有可能动态使用include在HTML中。

希望下面的例子能说明我要做的事情。

提前致谢
Adam

< script language =" javascript">
有趣ction checkFileToInclude(){
if(location.search =="?file1"){
return"<! - #include file =''file1.html'' - >
} else {
return"<! - #include file =''file2.html'' - >"
}
}
< / script>
< html>


< a href =" www.mydomain.com/test?file1" >包含文件1< / a>
< a href =" www.mydomain.com/test?file2">包含文件2< / a>


< td>
document.write(checkFileToInclude())
< / td>




< / html>
Hi All,

Is it possible to use includes dynamically in html.

Hopefully the following example will give an idea what I am rying to do.

Thanks in advance
Adam

<script language="javascript">
function checkFileToInclude(){
if (location.search == "?file1"){
return "<!--#include file=''file1.html''-->"
}else{
return "<!--#include file=''file2.html''-->"
}
}
</script>

<html>
.
.
<a href="www.mydomain.com/test?file1">Include File 1</a>
<a href="www.mydomain.com/test?file2">Include File 2</a>
.
.
<td>
document.write(checkFileToInclude())
</td>

.
.
.
</html>



除了两个回复之外,您还可以尝试使用对象元素

而不是服务器端包含,它允许您处理对象的内容

,如内联框架。即,

< object id =" file1"数据= QUOT;&的file1.html QUOT;类型= QUOT; text / html的" width =" 100%"

standby ="正在加载file1.html ...">

您的浏览器无法呈现嵌入的HTML文档。

< / object>

区别在于你的file1.html文档应该是一个有效的HTML

文档,而不仅仅是一个HTML片段。您可以通过对象的contentDocument属性访问该文档

。我已经使用这种方法在我的网站上包含全网菜单。


In addition to the two replies, you can also try using object elements
instead of server-side includes, which allows you to treat the content
of an object like an inline frame. Ie.,
<object id="file1" data="file1.html" type="text/html" width="100%"
standby="Loading file1.html...">
Your browser cannot render embedded HTML documents.
</object>
The difference is that your file1.html document should be a valid HTML
document, not just an HTML fragment. You can access that document
through the object''s contentDocument property. I''ve used this method to
include sitewide menus on my websites.


这篇关于动态包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆