【问题标题】:Related link for the device viewing设备查看相关链接
【发布时间】:2013-09-04 09:58:35
【问题描述】:

我想以与当前相同的布局向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。显然,在这种情况下,只有第 3 个链接应该是可见的,而其他 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>

请提供有关如何使其工作的任何想法。谢谢你。

【问题讨论】:

  • 所以你想要这样的东西:如果有人带着安卓设备来到你的移动网站,应用下载链接有这个:apps.php?id=android ?我说的对吗?
  • 嗨。是的,你完全正确。 iPhone/iPod touch 的 ?id=iPhone 和 iPad mini 和 iPad ?id=iPad 欢呼也是如此。

标签: php android ios device


【解决方案1】:

我已经想通了。

通过使用此代码:

>      <?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。

【讨论】:

    【解决方案2】:

    您可以在 PHP 中使用这些检测操作系统:get_browser()$_SERVER['HTTP_USER_AGENT'] 如果您想知道用户代理为您提供了什么,当安卓或 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>
    

    【讨论】:

    • 我在上面添加了一些代码。他们只是似乎不起作用。请你能告诉我为什么。谢谢,
    • 你需要这样使用:window.navigator.userAgent.match('iPhone') != null 当然,在 iPhone 和 iPad 上,Android 是好的。所以你有 3 个错误
    • 哦,iPad保护套永远不会用,因为iPhone一直是真的,它不会出去,它会停在那里。
    • 在我的 iPad 上,你的代码根本没有显示。还有其他方法吗?谢谢
    • 嗨。我已经对此进行了排序。使用我的答案。请 1up 我的回答。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 2016-03-03
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    相关资源
    最近更新 更多