SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2006
    Location
    High Wycombe UK.
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    player.addEventListener('onStateChange', 'onytplayerStateChange') and IE

    So, this is definatly one of the worst times i ever had with javascript and the blatent incompitancy of IE, below is my code, i realise that IE does not know of "addEventListener" although support was surpossed to be added in IE9 which still does not work, i have tried every fix i can think of and done all the research i can do on something that should just work anyway.

    Code:
    		google.load("swfobject", "2.1");
    		var fired = 0;
    		$(document).ready(function(){
    			track(getQueryString()["vid"]);
    		});
    		function getQueryString() {
    			var result = {},
    				queryString = location.search.substring(1),
    				re = /([^&=]+)=([^&]*)/g,
    				m;
    
    			while (m = re.exec(queryString)) {
    				result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
    			}
    			return result;
    		}
    
    		function track (vid) {
    			var params = {
    				allowScriptAccess: "always"
    			};
    			var atts = {
    				id: "player"
    			};
    			var urlString = "http://www.youtube.com/v/" + vid + "&enablejsapi=1&playerapiid=ytplayer";
    			swfobject.embedSWF(urlString, "embed", "640", "390", "10", "8", null, null, params, atts);
    		}
    			
    		function onYouTubePlayerReady(playerId){
    			var player = document.getElementById("embed");
    			player.addEventListener('onStateChange', 'onytplayerStateChange');
    		}
    		   
    		function onytplayerStateChange(newState){
    			if(newState != -1 && newState != 5 && !fired){
    				fired = 1;
    				var trackingPixel = new Image();
    				trackingPixel.src = getQueryString()["unloadUrl"];
    			}
    		}
    The function "onYouTubePlayerReady" does not get fired by IE for some(no) reason.

    There are many threads on this issue but none seem resolved.

    See it in action here: http://www.the7thchamber.com/swarm-e...id=jGUADHvbiC8

    Thanks for any help, this has been a very trying time for me, sometimes i love javascript but IE forces me to hate it, nothing like spending 30mins coding something then 4 hours making it work in IE.

    Cheers,
    Nick
    Never stop kicking me.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't know about IE9, but for IE it uses attachEvent()
    http://www.quirksmode.org/js/events_advanced.html

    But you are using jQuery in your example, so why not use .bind()?
    http://api.jquery.com/bind/

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2006
    Location
    High Wycombe UK.
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried both, i believe addEventListener('onStateChange', 'onytplayerStateChange'); to be part of the google SWF api in some way because it shouldn't work in FF without a 3rd parameter yet it does, so i think they have patched that function to work in all browsers (or at least tried).

    I have tried embedding the player with a jQuery SWF plugin but found you need to embed it with the google SWF to fire events of the video, or at least, thats what i have deducted from it(http://jquery.thewikies.com/swfobject/).

    Also using the IE developer toolbar, i have ensured i have it set to the normal IE9 mode, quirks is just pure fail on any page. I think the best place to start would be to find out why onYouTubePlayerReady is not firing but i google it and ive already read through everything.....

    Thanks anyway
    Never stop kicking me.

  4. #4
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you first attend to the error indicated in IE's console?
    Tab-indentation is a crime against humanity.

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2006
    Location
    High Wycombe UK.
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had not realized there was an error, i just put it to version 2.2 from 2.1 SWF however, since the error is in the framework, there is nothing i can do about it but post a thread. Thanks anyway, if you could give me some advice? that would be great.
    Never stop kicking me.

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2006
    Location
    High Wycombe UK.
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Changing it to load SWFobject 2.1 resolved the error, however it still does not work in IE.
    Never stop kicking me.


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
  •