如果不加载,则替代WebGL

时间:2012-09-25 15:10:13

标签: php javascript html webgl alt

我在iframe中有一些WebGL内容。在某些Web浏览器或旧计算机上,iframe未加载。当发生这种情况时,我想加载一个图像。是否有可能,如果是的话怎么做?

由于

2 个答案:

答案 0 :(得分:1)

支持WebGL是否支持最好以与Javascript相同的方式进行检查

WebGLRenderingContext gl = canvas.getContext("experimental-webgl")

if(!gl)
{
    $("#image").show()
}

答案 1 :(得分:1)

<script>中的问题:

首先,您的<script>代码中似乎存在一些问题。 <center><iframe ...标记内有简单的<script> HTML标记,但这不起作用,因为此处只应有javascript。还有一些缺少;个分号。

检测WebGL的解决方案:

您可以试试这个,但我也建议在我的答案结尾处查看链接的网站:

?>
<script type="text/javascript">
if (!window.WebGLRenderingContext) {
    var myImage = new Image();
    myImage.src = "http://domain.tld/picture.jpg";
    $(myImage).prependTo(document.body);
} else {
    $(document.body).prepend('<center><iframe ALLOWTRANSPARENCY="true" frameborder="0" height="340" width="454" src="CORRECT THIS FIELD"></iframe></center>');
}
</script>
<?php

只需为PHP添加echos并更正<iframe src="CORRECT THIS FIELD">属性,同时将图片网址设置为真正存在的内容。

代替document.body您可以使用例如'#myWebGLArea'并将<div id="myWebGLArea"></div>添加到您的网页。

更多主题:

同时查看https://gist.github.com/1709384处的WebGL检测脚本和另一个Q / A https://stackoverflow.com/a/9904965/1338846