admin管理员组文章数量:1317906
I am making a responsive website and I want to be able to use javascript to get the screen size and then render a coldfusion include depending on the screen size. Something like this:
if (screen.width <= 700) {
<cfinclude template="file1.cfm">
} else {
<cfinclude template="file.cfm">
}
I've also tried loading via .ajax() but I get stuck when I have include files inside the cfm file in already want to include.
I am making a responsive website and I want to be able to use javascript to get the screen size and then render a coldfusion include depending on the screen size. Something like this:
if (screen.width <= 700) {
<cfinclude template="file1.cfm">
} else {
<cfinclude template="file.cfm">
}
I've also tried loading via .ajax() but I get stuck when I have include files inside the cfm file in already want to include.
Share Improve this question asked Mar 5, 2012 at 19:08 meijiOrOmeijiOrO 4264 gold badges7 silver badges16 bronze badges 1- Do file.cfm and file1.cfm include HTML or JavaScript as their output content? – Jake Feasel Commented Mar 6, 2012 at 5:14
3 Answers
Reset to default 5JavaScript is client side. ColdFusion is server side. If you want to mix the two, you need Ajax. You should try something more like using jQuery for easy Ajax:
// LOOK AT THE SCREEN WIDTH
if (screen.width <= 700) {
// LOAD THE PAGE INTO THE CORRECT SIZED DIV
$("#YourDiv").load("ColFusionFile-01.cfm");
} else {
// LOAD THE PAGE INTO THE CORRECT SIZED DIV
$("#YourDiv").load("ColFusionFile-02.cfm");
}
Or, you might want to redirect them:
// LOOK AT THE SCREEN WIDTH
if (screen.width <= 700) {
// SEND THE VISITOR TO THE CORRECT SIZED PAGE
window.location.href = "ColFusionFile-01.cfm"
} else {
// SEND THE VISITOR TO THE CORRECT SIZED PAGE
window.location.href = "ColFusionFile-02.cfm"
}
You should be using CSS media queries and stylesheets for different display rendering based on screen size. This will allow you to have one CF page for both displays. No AJAX needed.
W3C documentation on Media Queries: http://www.w3/TR/css3-mediaqueries/
Great article on "Responsive Web Design": http://www.alistapart./articles/responsive-web-design/
Here are some awesome examples of sites that use this technique:http://mediaqueri.es/
What you are trying to do is not possible. JavaScript is a client side language, ColdFusion is a server side language. You cannot do a cfinclude in a block of JavaScript as that code will be executed in the browser, not on the server.
本文标签: javascriptcoldfusion after screen size detectionStack Overflow
版权声明:本文标题:javascript - coldfusion after screen size detection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742016081a2413794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论