Do I still need to test different types of browsers for JavaScript?

This is probably a simple question and I am a little confused to ask this, but I worked with this piece of JavaScript ad code for a while and it bothered me that it never made sense to me and probably from modern browsers. My question is, do I still need to check the types of browsers and what is this second bit of the script?

<script type="text/javascript">
  document.write('<scr' + 'ipt src="" type="text/javascript"></scr' + 'ipt>');
</script>
<script type="text/javascript">
  if ((!document.images && navigator.userAgent.indexOf('Mozilla/2.') >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {
    document.write('<a href="">');
    document.write('<img src="" border="0" alt="" /></a>');
  }
</script>

      

I would like to clarify that I actually find someone with some kind of ad code, so while I can check the browser types, it will actually be the responsibility of the code guardian. I would love it if I could get this in jQuery, but I am having trouble calling (see my other post below).

What I was wondering is I still need to check these types of browsers?

Cheers,
Steve

0


source to share


5 answers


In the second code snippet: it checks two things:

  • That the browser opening the document supports the Document.images DOM part of the document, that the document contains any images, and that the browser's UserAgent string (id) contains "Mozilla / 2.",
  • OR that the UserAgent string contains "WebTV"


in these cases, it outputs an empty link and an image tag.

+1


source


We mostly use javascript libraries like jQuery that handle this kind of thing for us.



It's weird that I find myself hacked for every browser CSS a lot more often these days.

+5


source


Better to check if the DOM browser DOM supports certain features rather than accessing the user agent string directly.

+2


source


This is why APIs (such as jQuery) are used. They offload an action to check browser compatibility (and future compatibility) with the developer. When there is a new browser or a new version of the browser, the API is updated as needed to keep your code running.

So, see if you can find a solution with jQuery and you don't have to worry about it. For future compatibility, you may need to get the latest jQuery, but the theory is that your code doesn't need to be updated.

0


source


It's nice to hear that a lot of people advocate jQuery, but the code I'm adding targets an external script that I don't have, and my problem is that whenever I call this script with jQuery, the declarations are opened on their own page:

$(this).append().html('<script src="http://ad.doubleclick.net/adj/' + site + '.iclick.com/adtarget;subss=' + subss + ';subs=' + subs + ';area=' + area + ';site=' + site + ';kw=' + kw + ';sz=' + $adSize + ';pos=' + count + ';tile=' + tilecount + ';ord=' + zzzzadslotzzzz + '"></script>');

      

I would like to transfer this stuff to jQuery (and this is my goal since I want to stop the ad from showing until the document is ready)

Thanks
Steve

0


source







All Articles