通过JavaScript获取page / iframe的编码 [英] Get encoding of page/iframe via JavaScript

查看:62
本文介绍了通过JavaScript获取page / iframe的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式通过JavaScript或浏览器中的其他API来确定页面的编码。我想要这些信息的原因是因为我试图模仿主要浏览器他们支持的字符编码,显然只是因为我发送了相应的Content-Type并不意味着浏览器会使用编码做正确的事情。任何其他可能的方法都是受欢迎的,但我不想点击页面信息进行50多个字符编码。

I'd like to programatically determine the encoding of a page via JavaScript, or some other API from a browser. The reason I want this information is because I am attempting to fuzz major browsers on what character encodings they support, and obviously just because I sent the appropriate "Content-Type" doesn't mean that the browser will do the right thing with the encoding. Any other possible methods would be welcome, but I would rather not click "Page Info" for 50+ character encodings.

推荐答案

Javascript只能报告正在发生的一些事情。大多数浏览器都不会为您提供足够有用的设置,以便您进行任何核心测试。

Javascript can only report some of the things that are going on. Most browsers won't expose enough useful settings to you for you to base any hardcore tests on.

有些内容如 document.inputEncoding document.characterSet (非IE), document.charset document.defaultCharset (IE)可能会让你有所帮助那里的方式。但这些可能与实际支持一样脆弱。也就是说,如果浏览器认为它支持编码但实际上不支持,那么这不是你想知道的吗?

There are things such as document.inputEncoding, document.characterSet (non IE), document.charset, and document.defaultCharset (IE) which might get you some of the way there. But these might be as flaky as the actual support. That is, if a browser "thinks" it supports an encoding but really doesn't, isn't that something you want to know?

我认为你最好的选择是设置一个动态测试页面上有一些相当困难的字符(或一个非常大的测试集),在浏览器中加载测试,让浏览器报告浏览器ID字符串,编码设置,原始编码请求和<$的内容c $ c> testElement.innerHTML 然后您可以根据预期结果进行验证。

I think your best bet is to set up a dynamic test page with some fairly difficult characters on it (or a really large test set), load test in a browser, have the browser report back browser id string, encoding settings, original encoding request, and contents of testElement.innerHTML which you can then verify against expected results.

这篇关于通过JavaScript获取page / iframe的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆