3

我的网站上的每个页面都包含一个自我刷新的隐藏 iframe。每次刷新时,它都会检查数据库中是否有任何新警报(该网站使用经典 ASP 编码)。如果 iframe 加载并找到新警报,它将有一个 embed 标记来播放 mp3 通知声音。

我的问题是,当 iframe 加载 embed 标记时,如果用户当时正在输入,光标将失去对任何文本字段的关注。

这在 Safari、FireFox 或 Chrome 中似乎不是问题……只有 IE,我正在运行 IE 9。这是我第一次敢在这个网站上添加音频……如果我至少可以使用所有提到的浏览器的最新版本,我会很高兴。

这是我的嵌入标签:

<embed hidden="true" autoplay="true" src="/AllInclude/Sounds/Notification_1.mp3" height="0px" style="overflow:hidden"></embed>

这是我的代码,其中包含 iframe:

<iframe src="/AllInclude/AlertChecker.asp" style="overflow:hidden;height:0px;position:absolute;top:-1000px" frameborder="no"></iframe>

这是我的 iframe 用来刷新自身的内容:

<script type="text/javascript"> 
setTimeout ('ReloadPage()', 15000 ); 
function ReloadPage() { 
window.location = window.location; 
}
</script>

谢谢!

更新:

我能够获得 html5 音频标签的工作版本来代替嵌入标签......但是,由于音频标签是 html5,我需要在每个页面中添加“DOCTYPE html”标签才能工作IE。这个标签对我的旧 ASP 网站造成了巨大的兼容性问题......所以不幸的是,html5 不是一个选项。

4

2 回答 2

1

你可以使用:

iframe 而不是音频或嵌入标签

<iframe id="iframe" src="blank.html" disable="disabled" style="position:absolute;top:-10px;></iframe>
<!--You will need to save a blank html file as blank.html"/-->
<script type="text/javascript'>
/* 
add the condition for audio to load 
*/
document.getElementById("iframe").src="AllInclude/Sounds/Notification_1.mp3"
</script>

不过,我建议将它与上面列出的其他选项结合起来......

于 2012-10-28T02:11:05.417 回答
0

好吧,好吧,在没有找到解决这个问题的好方法后,我决定给 Adob​​e Flash 一个机会,它似乎是目前最好的选择。它不是很漂亮,也不是我想让它工作的方式,但它可以工作(并且大多数人都安装了 Flash)。

无论如何,在这里我找到了一个可以自动启动的免费 Flash 音频播放器:

http://wpaudioplayer.com/standalone/

这是我的代码的样子(它只为 IE 实现了 flash 播放器,因为 embed 标记在其他浏览器上工作得很好):

<%
BrowserType = lcase(Request.ServerVariables("HTTP_USER_AGENT"))
if onload <> "" AND InStr(BrowserType,"msie") > 0 then
%>
    <script type="text/javascript" src="/AllInclude/JS/audio-player.js"></script>  
    <script type="text/javascript">AudioPlayer.setup("/AllInclude/Flash/player.swf", {width: 290, autostart: "yes"});</script>
    <p id="audioplayer_1">Alternative content</p>
    <script type="text/javascript">AudioPlayer.embed("audioplayer_1", {soundFile: "/AllInclude/Sounds/Notification_1.mp3"});</script>
<% elseif onload <> "" then %>
    <embed hidden="true" autoplay="true" src="/AllInclude/Sounds/Notification_1.mp3" height="0px" style="overflow:hidden;"></embed>
<% end if %>
于 2012-10-05T15:07:45.407 回答