Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
83
rated 0 times [  87] [ 4]  / answers: 1 / hits: 71774  / 12 Years ago, thu, may 10, 2012, 12:00:00

Im pretty sure my syntax this wrong because the script only works if the string matches Video, if the string has the word Audio it is ignored. Also since the href tags have a value of # the redirect for ../../../index.html doesnt work.



js



var ua = navigator.userAgent.toLowerCase();
var isIE8 = /MSIE 8.0/i.test(ua);
if (isIE8) {
$('a').click(function () {
var srcTag = $(this).find('img').attr('src');
if (srcTag.indexOf('Video' || 'Audio') > -1) {
if (confirm('Download Safari? nn http://apple.com/safari/download/')) {
window.location = 'http://apple.com/safari/download/';
} else { window.location = '../../../index.html';}
} else {
alert('no match');
}
});
}


html



<a href=#><img src=Video/000_Movies/assets/005_CCC_Jesus_Story_80x60.jpg />test1</a> 
<a href=#><img src=Audio/000_Movies/assets/006_GSP_Gods_Story_80x60.jpg />test2</a>
<a href=#><img src=Media/000_Movies/assets/002_God_Man_80x60.jpg />test3</a>

More From » jquery

 Answers
4

It's far shorter to turn this into a regular expression.



if ( srcTag.match( /(video|audio)/ ) ) {
/* Found */
} else {
/* Not Found */
}


On a side note, please don't do what you're attempting to do. Asking users to download Safari when they're using Internet Explorer 8 is doing a disservice to the Internet, as well as to that user.



As for redirecting the domain to another location, you should use .preventDefault() to keep the browser from following the link:



$(a.videoDownload).on(click, function(e){
e.preventDefault();
if ( this.getElementsByTagName(img)[0].src.match( /(video|audo)/ ) ) {
window.location = confirm( 'Download Safari?' )
? http://apple.com/safari/download
: ../../../index.html ;
} else {
/* No match */
}
});


Again, please don't actually do this. Nobody wants to be that guy, and when you tell users to download another browser, you're being that guy.


[#85668] Wednesday, May 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deanna

Total Points: 84
Total Questions: 86
Total Answers: 107

Location: Cyprus
Member since Wed, Dec 8, 2021
3 Years ago
;