what do you expect? onload fires the function only after the document is fully loaded. But it will not have the time to be loaded, because the location is changed immediately by the code line
I am actually writing a chrome extension right now. It treats the youtube page that I open. It will change the quality of the player right after the page is loaded. So I need to implement the onload function.
But I am testing the code in a html editor, so I would firstly load a youtube page (that's why I need the location = 'url' line), and see what I can do with the onload function (because I will call youtube API function setPlaybackQuality('hd720') inside the onload function).
But clearly that I am not able to do it that way according to your instruction. So what's your suggestion?
You can't do that in that way. You should load the API codes and the Flash application in your document, as external elements. Now you can call the API method onload, because both the API and the movie are within your document.
You can't do that in that way. You should load the API codes and the Flash application in your document, as external elements. Now you can call the API method onload, because both the API and the movie are within your document.
Thanks for your suggestion. Actually I tried to load the video and used the API functions, and they worked perfectly.
But the problem is that when I do it in chrome extension, the page is already there. I do not need to load any video or API functions, because the extension will be triggered when the youtube web pages are opened. So what have to do is invoke a youtube API function setPlaybackQuality(hd720'). I put this in the js file of the extension and I fond that this API function is not defined at all.
And I get a tip from another guy tells that the js file lives in a different world of the page, which means I can not call the function of the API from the page I opened. That's why I tried to use the locate function and call the API function when the page is loaded.
That guy suggested me to try to take action on the DOM of the youtube page, which is like:
location.href="javascriptlayer = document.getElementById('movie_player');player.setPlaybackQuality('hd720');void(0)";
And I found that setPlaybackQuality still not defined in this section, so it did not work out neither.
So bascly what I need now is to figure out how to call this API function inside the js file(this file is in a different world of the youtube page).
Bookmarks