最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - coldfusion after screen size detection - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 5

JavaScript 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.

发布评论

评论列表(0)

  1. 暂无评论