根据用户屏幕大小加载 js 或 php [英] load js or php based on users screen size

查看:16
本文介绍了根据用户屏幕大小加载 js 或 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 Swiffy (HTML5 SWF) 动画,我只想根据用户屏幕尺寸加载它们!

I have a couple of Swiffy (HTML5 SWF) animations which i only want to be loaded based on the users screen size!

iv 在下面找到了一些 JavaScript,它说如果屏幕大于 1400 它将加载但它不起作用!

iv found some JavaScript below which says it will load if screnn bigger than 1400 but its not working!

<script language=javascript>
if(screen.Width>1400)
{
    document.write("<?php include('/map/map4.php');?>");
}
else
{
    document.write("<?php include('/map/map1.php');?>");
}
</script>

有没有人知道用上述方法或其他方法来做这件事?

dose any one know of away to do this either with the above or another way?

谢谢

推荐答案

改变这个:

if(screen.Width>1400)

到:

if (screen.width > 1400)

screen 对象的

width 属性应该是小写的.

width property of the screen object should be lowercase.

还要注意,当JavaScript执行完ServerSide处理结束,你的document.write只输出文本而不是可执行的php代码,可以使用load方法取而代之的是 jQuery.

Also note that when JavaScript is executed ServerSide processing is ended, and your document.writes only output text instead of executable php codes, you can use the load method of the jQuery instead.

从服务器加载数据并将返回的 HTML 放入匹配的元素中.

Load data from the server and place the returned HTML into the matched element.

if (screen.width > 1400) {
     $('#wrapper').load('/map/map4.php');
} else {
     $('#wrapper').load('/map/map1.php');
}

这篇关于根据用户屏幕大小加载 js 或 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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