www.webdeveloper.com
Results 1 to 8 of 8

Thread: HELP: onload not work after a webpage load call!

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    7

    HELP: onload not work after a webpage load call!

    Please look at the following code, and tell me why the onload function is not called.


    <html>
    <body>

    <script type="text/javascript">
    location = 'http://www.youtube.com/watch?v=FO52eCNTdRc&feature=popt14us02';

    function oknow(){
    alert("window onload");
    }

    window.onload = oknow;
    </script>

    </body>
    </html>

    Thanks a lot!

  2. #2
    Join Date
    May 2010
    Location
    Connecticut
    Posts
    19
    ive had a similar problem. its not as elegant, but it works better to make your body tag
    HTML Code:
    <body onload="oknow()">

  3. #3
    Join Date
    May 2010
    Posts
    7

    Unhappy

    Quote Originally Posted by eastsideski View Post
    ive had a similar problem. its not as elegant, but it works better to make your body tag
    HTML Code:
    <body onload="oknow()">
    Thanks for your reply. Do you mean by:


    <html>
    <body onload="oknow()">

    <script type="text/javascript">
    function oknow(){
    alert("window onload");
    }

    //window.onLoad = oknow;

    location = 'http://www.youtube.com/watch?v=FO52eCNTdRc&feature=popt14us02';


    </script>

    </body>
    </html>

    But this is still not working>

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by eastsideski View Post
    ive had a similar problem. its not as elegant, but it works better to make your body tag
    HTML Code:
    <body onload="oknow()">
    no. It is absolutely the same thing.

  5. #5
    Join Date
    May 2010
    Posts
    7
    Quote Originally Posted by Kor View Post
    no. It is absolutely the same thing.
    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?

    Thanks a lot for your attention and your time!

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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

    location = 'http://www.youtube.com/watch?v=FO52eCNTdRc&feature=popt14us02';

    runs, thus the session changes before the full loading of the document in the first session.

    Tell, us, in fact, which is your real need? What do you want to do and why?

  7. #7
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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.

  8. #8
    Join Date
    May 2010
    Posts
    7
    Quote Originally Posted by Kor View Post
    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).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles