从移动浏览器中运行中排除代码
Exclude Code from Running in Mobile Browser
有没有人知道一些代码,我可以用来排除某些内容在移动浏览器中显示。
我特别想排除某些图像和闪存文件在网站上显示 - 但仅限于在移动浏览器上查看时。
像这样的东西,但不知道"代码"是什么。
<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';
}
}
}
我承认我个人并不关注这里发生的一切,但我认为这些例子和两个不同的链接可以以某种方式给你你想要的结果。
相关文章:
- 从桌面读取python文件时高亮显示代码
- 如何将函数包装在函数中以避免代码重复
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- 货币代码为欧元-金额的格式不应包含小数
- Regex代码只允许一个空格
- 如何将屏幕分辨率乘以 80%,然后在代码中使用
- 从IntelliJ IDEA的代码完成中排除javascript库
- 如何使用 Webpack 和 Babel 从 Karma 的代码覆盖率中排除规范文件
- 从移动浏览器中运行中排除代码
- 我需要对我的HTML/JavaScript代码进行一些故障排除
- 对接收到错误消息的JS代码段进行故障排除.验证错误是否正确
- Nashorn故障排除”;方法代码太大"例外
- 需要帮助对学校项目的html文件中的Javascript代码进行故障排除
- 如何在与webpack/browsrify绑定时排除代码路径
- RegExp排除代码和预标记之间的匹配
- Gulp插件包括/排除行JS代码取决于任务运行
- 只将JS代码添加到domain.com/blog/some-post/旁边的博客文章中,并排除在页面中
- 如何从这个javascript代码中排除容器
- 使用.show()和.hide()功能的JavaScript/JQuery代码的故障排除
- Browserify -排除代码块