查看设备的相关链接

时间:2013-09-04 09:58:36

标签: php android ios device

我想要使用与目前相同的布局向my site添加内容。

基本上,您可以在我的主页上看到类别列表。然后链接到我的list.php页面,其中包含反映标题的内容。

我正在寻找相同的东西,但我想要的是它显示apps.php而不是list.php,它做同样的事情,但不是按类型分类的内容我按照设备进行分类。例如apps.php?id = iphone。

我想要的是我的索引页面上的链接,如果他们使用相关设备,则会显示到此apps.php页面。

例如

标题为“app download”的链接将显示在iPhone / iPod touch上,链接到apps.php?id = iphone,androids链接将是apps.php?id = android和iPad mini相同和iPad,但没有任何东西将显示在其他设备上。

有人可以指导我如何做到这一点。谢谢。

我猜这可以通过以下代码完成:

<script type="text/javascript">
var bodyclass ='desktop';
if ( (navigator.userAgent.indexOf('Android') != -1) ) {
   bodyclass = 'android';
} else if((window.navigator.userAgent.match('iPhone'))||(window.navigator.userAgent.match('iPod'))) {
  bodyclass = 'iphone';
} else if (window.navigator.userAgent.match('iPad')){
  bodyclass = 'ipad';
}
window.onload = function(){
  document.body.className += ' '+ bodyclass;
} 
<script>

<ul class="pageitem"><li class="button iphone"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=iPhone' " type="submit" /></li></ul>

<ul class="pageitem"><li class="button ipad"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=iPad' " type="submit" /></li></ul> 

<ul class="pageitem"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=android' " type="submit" /></li></ul>

但它们似乎不起作用。

更新

如果您现在看一下我的iPad上的THIS PICTURE,您会看到3个应用下载按钮。顶部的一个链接到app.php?id = android中间的一个链接到app.php?id = iphone,底部链接到app.php?id = ipad。显然在这种情况下,只有第三个链接应该是可见的,另一个2隐藏,因为我正在我的iPad上查看。

如果我要在我的iPod touch上查看,那么只有中间的应该是可见的。

屏幕截图中index.php页面的代码是:

<?PHP 
include_once('include/connection.php'); 
include_once('include/article.php');

$category = new category;
$articles = $category->fetch_all();


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Xclo.mobi</title>

<link type="text/css" rel="stylesheet" href="other.css" />
<link rel="apple-touch-icon" href="homescreen.png" />
<link href="startup.png" rel="apple-touch-startup-image" />

<script type="text/javascript">
var bodyclass ='desktop';
if ( (navigator.userAgent.indexOf('android') != null) ) {
   bodyclass = 'android';
} else if((window.navigator.userAgent.match('iphone') != null)||(window.navigator.userAgent.match('iPod') != null)) {
  bodyclass = 'iphone';
} else if (window.navigator.userAgent.match('ipad') != null){
  bodyclass = 'ipad';
}
window.onload = function(){
  document.body.className += ' '+ bodyclass;
} 
<script>

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-34172259-1']);
_gaq.push(['_setDomainName', 'xclo.co.uk']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

</head>
<body>

<?php include_once('header.php'); ?>


<div id="content">

<ul class="pageitem"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=android' " type="submit" /></li></ul>

<ul class="pageitem"><li class="button iphone"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=iphone' " type="submit" /></li></ul>

<ul class="pageitem"><li class="button ipad"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=ipad' " type="submit" /></li></ul>


<?php foreach ($articles as $article) { ?>

<ul class="pageitem"><li class="button"> 
<a href="list.php?id=<?php echo $article['promo_cat']; ?>">
<input type="submit" name="Submit" value="<?php echo $article['promo_cat']; ?>"/>
</a></li></ul>
<?php } ?>




</div>
<br><center>
<SCRIPT charset="utf-8" type="text/javascript" src="http://ws-eu.amazon-...d9-6cf16307e855"> </SCRIPT> <NOSCRIPT><A HREF="http://ws-eu.amazon-...t">Amazon.co.uk Widgets</A></NOSCRIPT></center>

<?php include_once('footer.php'); ?>


</body>
</html>

有关如何让这个工作的任何想法,请。谢谢。

2 个答案:

答案 0 :(得分:0)

您可以使用PHP检测操作系统:get_browser()$_SERVER['HTTP_USER_AGENT'] 如果您想知道用户代理为您提供的服务,当Android或iPhone用户访问您的网页时,请访问this并选择希望您查看的操作系统。

您可以拆分或搜索字符串,这是您选择的选择。 (也许get_browser(NULL, true)是更好的选择。

如果您获得操作系统,请使用if,并打印该操作系统的代码。

编辑: 改变这些: 从:

var bodyclass ='desktop';
if ( (navigator.userAgent.indexOf('android') != null) ) {
   bodyclass = 'android';
} else if((window.navigator.userAgent.match('iphone') != null)) {
  bodyclass = 'iphone';
} else if (window.navigator.userAgent.match('ipad') != null){
  bodyclass = 'ipad';
}
window.onload = function(){
  document.body.className += ' '+ bodyclass;
} 

<ul class="pageitem"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=android' " type="submit" /></li></ul>

<ul class="pageitem"><li class="button iphone"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=iphone' " type="submit" /></li></ul>

<ul class="pageitem"><li class="button ipad"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=ipad' " type="submit" /></li></ul>

要:

var bodyclass ='desktop';
if ( (navigator.userAgent.indexOf('Android') != -1) ) {
   bodyclass = 'android';
} else if((window.navigator.userAgent.indexOf('iPhone') != -1)) {
  bodyclass = 'iphone';
} else if (window.navigator.userAgent.indexOf('iPad') != -1){
  bodyclass = 'ipad';
}
window.onload = function(){
  if(bodyclass != "desktop") document.getElementById(bodyclass).style.display="";
  document.body.className += ' '+ bodyclass;
} 

<ul class="pageitem" id="android" style="display:none;"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=android' " type="submit" /></li></ul>

<ul class="pageitem" id="iphone" style="display:none;"><li class="button iphone"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=iphone' " type="submit" /></li></ul>

<ul class="pageitem" id="ipad" style="display:none;"><li class="button ipad"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=ipad' " type="submit" /></li></ul>

答案 1 :(得分:0)

我已经弄明白了。

使用此代码:

>      <?php $ua=$_SERVER['HTTP_USER_AGENT']; switch(true) {   case
>       stripos($ua,'android') :
>        $device = 'android'; break;   case stripos($ua,'ipad') :
>         $device = 'ipad'; break;   case stripos($ua,'iphone') :
>         $device = 'iphone'; break; } ?>  
> 
> <ul class="pageitem"><li class="button android"><input name="Submit"
> value="App Downloads" onclick="window.location='apps.php?id=<?php echo
> $device; ?>' "
>          type="submit" /></li></ul>

谢谢。请1up。