SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard silver trophy
    Join Date
    Aug 2003
    Location
    Southern California
    Posts
    4,686
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)

    IE Specific: Javascript Does Not Execute Replacement on <a>

    We run a social sharing button and recently after upgrading to a dynamic javascript inclusion we've noticed that many version of Internet Explorer are not running / rendering out script at all. Chrome, Firefox, Safari, iOS, and anything else handle the button just fine.

    Because this sits on third party sites which can run a host of scripts [not to mention load time considerations] we're not able to take advantage of jquery or something else along those lines.

    Here's the code installed on a page:

    This in turn will pull up an iFrame in place of the link which connects to our processing server with variables from the link passed over to form the button.

    Code:
    (function(){	
    	var lnksNodeList = document.getElementsByTagName("a");
    	var lnks = Array.prototype.slice.call(lnksNodeList);
    	for (var i = 0; i < lnks.length; i++) {		
    		lnk = lnks[i]; ...
    It doesn't seem like IE is recognizing the replacement request at all as the output is simply the original, unformated text link.

    Any suggestions on where to start?
    Last edited by Ted S; May 30, 2012 at 22:00.
    - Ted S

  2. #2
    SitePoint Enthusiast aufshebung's Avatar
    Join Date
    May 2012
    Location
    Santa Fe, NM
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like you're trying to convert a NodeList into an Array! (Sorry, the ClippyJS thing has been stuck in my head...)

    Unfortunately, IE does not allow you to use Array.prototype.slice with a NodeList:

    Normally it wouldn't be legal to call Thing.prototype.method on anything but an instance of Thing, however browsers have traditionally allowed — and the ECMAScript Third Edition standard requires — a special case for many Array.prototype methods so that they can be called on any native-JavaScript object which is sufficiently like an Array. This means, notably, that they can be used on the arguments object, which looks like an Array but actually isn't.

    However, NodeList and the other collection objects in the DOM are not defined to be native JavaScript objects; they are allowed to be ‘host objects’, which are implemented completely by the browser and not the language. All bets are off for host objects...

    Whether the slice function can be applied successfully to a host object is implementation-dependent.
    So Array.prototype.slice may not work for NodeList, and in IE before version 8, indeed, it won't.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Aug 2003
    Location
    Southern California
    Posts
    4,686
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Clearly should have searched around more but that got me on the right path and the team made a simple change to remove the whole Array.prototype.slice.call which seems to be working fine. We'll have to benchmark more of course but rendering is at least correct now...
    - Ted S


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •