Javascript 当嵌入式链接不存在时,如何输出警报消息?
我有这段代码,我想知道当嵌入的链接不存在时,如何显示警报消息。这可能吗Javascript 当嵌入式链接不存在时,如何输出警报消息?,javascript,asp.net,ajax,forms,hyperlink,Javascript,Asp.net,Ajax,Forms,Hyperlink,我有这段代码,我想知道当嵌入的链接不存在时,如何显示警报消息。这可能吗 <script type="text/javascript"> function soniaZsound(track) { var link = 'https://ssl.gstatic.com/dictionary/static/sounds/de/0/'+track+'.mp3'; document.getElementById("myspan").innerHTML='<em
<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>
音响功能(音轨){
var-link=https://ssl.gstatic.com/dictionary/static/sounds/de/0/“+曲目+”.mp3';
document.getElementById(“myspan”).innerHTML='';
}
这个词听起来怎么样:
如果允许您从该域读取内容,您可以执行HTTP HEAD请求以查看文件是否存在:
$.ajax({
url:'http://www.example.com/somefile.ext',
type:'HEAD',
error:
function(){
//file does not exists
},
success:
function(){
//file exists
}
})) 如果允许您从该域读取内容,您可以执行HTTP HEAD请求以查看文件是否存在:
$.ajax({
url:'http://www.example.com/somefile.ext',
type:'HEAD',
error:
function(){
//file does not exists
},
success:
function(){
//file exists
}
})) 如果你得到这个错误是因为文件“loveu.mp3”不存在。顺便说一句,我认为该域不允许从另一个域打开内容。。。(我理解你的问题是错误的,好像你想检查嵌入标签的src。所以我删除了我的答案。)如果你得到这个错误是因为文件“loveu.mp3”不存在。顺便说一句,我认为该域不允许从另一个域打开内容。。。(我理解错了你的问题,好像你想检查嵌入标签的src。所以我删除了我的答案。)