从移动浏览器中运行中排除代码

Exclude Code from Running in Mobile Browser

本文关键字:排除 代码 运行 浏览器 移动      更新时间:2023-09-26

有没有人知道一些代码,我可以用来排除某些内容在移动浏览器中显示。

我特别想排除某些图像和闪存文件在网站上显示 - 但仅限于在移动浏览器上查看时。

像这样的东西,但不知道"代码"是什么。

<code><img src="smiley.gif" alt="Smiley face" width="32" height="32" /></code>

如果有人能够提供帮助,我将不胜感激。

似乎您可以使用这样的东西查找 META 标签

JavaScript:

var agent=navigator.userAgent.toLowerCase();
var is_iphone = ((agent.indexOf('iphone')!=-1);
if (is_iphone) { conditional code goes here }

使用它来设置变量,然后使用类似这样的东西来检查变量并显示/隐藏一些内容:

.XHTML:

<p>...This is all visible content... 
<a href="#" id="example-show" class="showLink" 
onclick="showHide('example');return false;">See more.</a>
</p>
<div id="example" class="more">
<p>...This content is hidden by default...</p>
<p><a href="#" id="example-hide" class="hideLink" 
onclick="showHide('example');return false;">Hide this content.</a></p>
</div>

.CSS:

.more {
    display: none;
    border-top: 1px solid #666;
    border-bottom: 1px solid #666; }
a.showLink, a.hideLink {
    text-decoration: none;
    color: #36f;
    padding-left: 8px;
    background: transparent url('down.gif') no-repeat left; }
a.hideLink {
    background: transparent url('up.gif') no-repeat left; }
a.showLink:hover, a.hideLink:hover {
    border-bottom: 1px dotted #36f; }

JavaScript:

function showHide(shID) {
    if (document.getElementById(shID)) {
        if (document.getElementById(shID+'-show').style.display != 'none') {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID).style.display = 'block';
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID).style.display = 'none';
        }
    }
}

我承认我个人并不关注这里发生的一切,但我认为这些例子和两个不同的链接可以以某种方式给你你想要的结果。