gpt4 book ai didi

javascript - 当嵌入链接不存在时如何输出警报消息?

转载 作者:行者123 更新时间:2023-11-28 02:05:57 25 4
gpt4 key购买 nike

我有这段代码,我想知道当嵌入链接不存在时如何显示警报消息。这可能吗?

<script type="text/javascript">
function soniaZsound(track) {
var link = 'https://ssl.gstatic.com/dictionary/static/sounds/de/0/'+track+'.mp3';

document.getElementById("myspan").innerHTML='<embed src="'+link+'"' +
'onError="alert("sorry this word is not in the database");"' +
'`autostart=true loop=false hidden=true` type="audio/mp3">';
}
</script>

<body>
<span id="myspan"></span>
<form name= "searchwords" id="searchwords">
How does this word sound: <input type="text" name= "soundSearch"><input type="button"
value="GO" onclick="soniaZsound(document.forms['searchwords']['soundSearch'].value);">
</form>
</body>

最佳答案

如果您被允许从该域读取内容,您可以执行 HTTP HEAD 请求来查看该文件是否存在:

$.ajax({
url:'http://www.example.com/somefile.ext',
type:'HEAD',
error:
function(){
//file does not exists
},
success:
function(){
//file exists
}

});

关于javascript - 当嵌入链接不存在时如何输出警报消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17757442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com