Is there a simple way to prevent browser from downloading and displaying images, best would be via some magic style tag or javasctipe.
是否有一种简单的方法可以防止浏览器下载和显示图像,最好通过一些魔术风格标签或javasctipe。
The thing is, I'd like to tweak the company's website a bit to be more usable via mobile devices. The company is a gaming one, there's like 5MBs of images on it's main page (and those can't be touched). They alredy display deadly slow on my dsl, and they can be killers to someone who's paying for his GPRS per MB ;)
问题是,我想通过移动设备调整公司的网站,以便更有用。该公司是一个游戏公司,它的主页面上有5MB的图像(这些图像无法触及)。他们在我的dsl上显示致命的速度,他们可以成为那些为每MB支付GPRS费用的人的杀手;)
The code of the page is not mine and shouldn't be touched too (in fact, it should be written from scratch, but it's not in my gesture to do it now) :)
页面的代码不是我的,也不应该被触及(事实上,它应该从头开始编写,但现在不是我的手势):)
I was thinking about two solutions:
我在想两个解决方案:
1) If there was some kind of style-tag (or maybe a javascript? the one that would work on mobile browsers tho) that would prevent browser from downloading images and force to display alt-parameter instead I could simply attach this style if I discovered a user-agent to be some known mobile thing. or 2) I could tweak the webserver a bit to check the User-agent header and if client requests an image (.png, .gif and .jpg) send 404 instead. That has a downside tho - I'd like to allow the user to view images if he actually wants to.
1)如果有某种样式标签(或者可能是javascript?那个可以在移动浏览器上使用的那个),这会阻止浏览器下载图像并强制显示alt-parameter而不是我可以简单地附加这种风格如果我发现用户代理是一些已知的移动东西。或者2)我可以稍微调整网络服务器以检查用户代理标头,如果客户端请求图像(.png,.gif和.jpg),则发送404。这有一个缺点 - 我想允许用户查看图像,如果他真的想。
It seems that first solution would be best - what you guys think? And is there a javascript way to do it?
似乎第一个解决方案是最好的 - 你们想的是什么?有没有一种javascript方式来做到这一点?
I could try building document DOM, then get all <img>
elements, and replace their src
with some placeholder even but will that work on most mobile browsers (Opera Mini I suppose, the Windows Mobile thingy, the basic Symbian browser from Nokia)? And would playing with document DOM be a good solution on a mobile device (I'm not sure about it's memory-and-cpu requirements to be honest).
我可以尝试构建文档DOM,然后获取所有元素,并用一些占位符替换他们的src,但是这适用于大多数移动浏览器(Opera Mini我想,Windows Mobile的东西,诺基亚的基本Symbian浏览器)?并且使用文档DOM在移动设备上是一个很好的解决方案(说实话,我不确定它的内存和CPU要求)。
4 个解决方案
#1
4
You can use htaccess to redirect image requests made from mobile browser users. I haven't tested this but it should work:
您可以使用htaccess重定向从移动浏览器用户发出的图像请求。我没有测试过这个,但它应该工作:
RewriteCond %{HTTP_USER_AGENT} (nokia¦symbian¦iphone¦blackberry) [NC]
RewriteCond %{REQUEST_URI} !^/images/$
RewriteRule (.*) /blank.jpg [L]
This code redirects all requests made to files in image folder by nokia,symbian,iphone and blackberry to a blank image file.
此代码将nokia,symbian,iphone和blackberry对图像文件夹中的文件所做的所有请求重定向到空白图像文件。
#2
1
I would not rely on javascript or any other client side method with mobile browsers. Most mobile browsers just don't support javascript well enough.
我不会依赖javascript或任何其他客户端方法与移动浏览器。大多数移动浏览器都不支持javascript。
Some server side "branching" is probably the way to go. And don't forget to disable the css background images while you're at it.
一些服务器端“分支”可能是要走的路。并且不要忘记在你使用时禁用css背景图像。
#3
0
Why not use alternative style sheets? I just don't know how well they are supported by mobile browsers.
为什么不使用替代样式表?我只是不知道移动浏览器对它们的支持程度如何。
You can specify a seperate css for mobile devices:
您可以为移动设备指定单独的css:
<link rel="stylesheet" media="screen,projection,tv" href="main.css" type="text/css">
<link rel="stylesheet" media="handheld" href="smallscreen.css" type="text/css">
In that css you override the display of <img>
and all background pictures.
在该css中,您将覆盖和所有背景图片的显示。
#4
0
That's like spoofing your user agent. If they really want the full version, just give it to them. Maybe add a suggestion to Blackberry users to complain with the manufacturer about the lack of such an option.
这就像欺骗你的用户代理。如果他们真的想要完整版,那就给它们吧。也许向Blackberry用户添加一个建议,向制造商抱怨缺少这样的选项。
#1
4
You can use htaccess to redirect image requests made from mobile browser users. I haven't tested this but it should work:
您可以使用htaccess重定向从移动浏览器用户发出的图像请求。我没有测试过这个,但它应该工作:
RewriteCond %{HTTP_USER_AGENT} (nokia¦symbian¦iphone¦blackberry) [NC]
RewriteCond %{REQUEST_URI} !^/images/$
RewriteRule (.*) /blank.jpg [L]
This code redirects all requests made to files in image folder by nokia,symbian,iphone and blackberry to a blank image file.
此代码将nokia,symbian,iphone和blackberry对图像文件夹中的文件所做的所有请求重定向到空白图像文件。
#2
1
I would not rely on javascript or any other client side method with mobile browsers. Most mobile browsers just don't support javascript well enough.
我不会依赖javascript或任何其他客户端方法与移动浏览器。大多数移动浏览器都不支持javascript。
Some server side "branching" is probably the way to go. And don't forget to disable the css background images while you're at it.
一些服务器端“分支”可能是要走的路。并且不要忘记在你使用时禁用css背景图像。
#3
0
Why not use alternative style sheets? I just don't know how well they are supported by mobile browsers.
为什么不使用替代样式表?我只是不知道移动浏览器对它们的支持程度如何。
You can specify a seperate css for mobile devices:
您可以为移动设备指定单独的css:
<link rel="stylesheet" media="screen,projection,tv" href="main.css" type="text/css">
<link rel="stylesheet" media="handheld" href="smallscreen.css" type="text/css">
In that css you override the display of <img>
and all background pictures.
在该css中,您将覆盖和所有背景图片的显示。
#4
0
That's like spoofing your user agent. If they really want the full version, just give it to them. Maybe add a suggestion to Blackberry users to complain with the manufacturer about the lack of such an option.
这就像欺骗你的用户代理。如果他们真的想要完整版,那就给它们吧。也许向Blackberry用户添加一个建议,向制造商抱怨缺少这样的选项。