我正在尝试基于rails中的浏览器进行一些操作。所以我的index.rhtml里有这个
<div class="function_tes">
<function whichBrwsr()
{
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("msie") != -1) return 'IE';
if (agt.indexOf("firefox") != -1) return 'Firefox';
}>
</div>但是,当我在"IE“或"firefox”浏览器中打开索引时,我看不到任何结果。我是否需要在index.rhtml或中的某个地方调用whichBrwsr()?
感谢您的指导
发布于 2010-11-12 04:44:24
这就是你要的。
<div id="myDiv" class="function_tes">
</div>
<script type="text\javascript">
function whichBrwsr()
{
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("msie") != -1) return 'IE';
if (agt.indexOf("firefox") != -1) return 'Firefox';
}
document.getElementById("myDiv").innerHtml = whichBrwsr();
</script>https://stackoverflow.com/questions/4159058
复制相似问题