473,395 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

onLoad Function in Javascript

I'm working to get the onLoad function of a javascript to work:
the script allows form buttons in html to refer to labeled frames in flash. Which works fine.

Now I want to add onLoad functionality to force the flash file to jump to a labeled frame on load.

This is the Javascript in the head of the html file:

Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. function getFlashMovieObject(movieName)
  3. {
  4.   if (window.document[movieName]) 
  5.   {
  6.     return window.document[movieName];
  7.   }
  8.   if (navigator.appName.indexOf("Microsoft Internet")==-1)
  9.   {
  10.     if (document.embeds && document.embeds[movieName])
  11.       return document.embeds[movieName]; 
  12.   }
  13.   else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  14.   {
  15.     return document.getElementById(movieName);
  16.   }
  17. }
  18.  
  19. function GotoLabelStart()
  20. {
  21.     var flashMovie=getFlashMovieObject("myFlashMovie");
  22.     flashMovie.TGotoLabel("/", "start");
  23. }
  24. //-->
  25.  
By using a form and form buttons the script jumps to a frame labelled 'Start'.

Expand|Select|Wrap|Line Numbers
  1. <input type="button" value="Start" name="Start" onclick="GotoLabelStart();" />
  2.  
I tried several solutions I've found on the net to make the onLoad function to work, please note that it needs to work for Safari on Mac aswell.

SOLUTIONS tried and not working:

1. <body onload="GotoLabelStart();">

2. Added another js:
Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. function addLoadEvent(func) {
  3.   var oldonload = window.onload;
  4.   if (typeof window.onload != 'function') {
  5.     window.onload = func;
  6.   } else {
  7.     window.onload = function() {
  8.       oldonload();
  9.       func();
  10.     }
  11.   }
  12. }
  13.  
  14. addLoadEvent(GotoLabelStart);
  15. addLoadEvent(function GotoLabelStart()
  16. {
  17.     var flashMovie=getFlashMovieObject("myFlashMovie");
  18.     flashMovie.TGotoLabel("/", "start");
  19. }
  20. );
  21. //-->
  22.  
3. Another js I tried was :
Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. window.onload=function GotoLabelStart()
  3. {
  4.     var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "start");
  6. }
  7. //-->
  8.  
4. Another thing I tried was adding :
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function load()
  3. {
  4. var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "terug");
  6. }
  7. </script>
  8. </head>
  9. <body onload="load()">
  10.  
5. Another thing I tried:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/JavaScript">
  2. <!--
  3. function GotoLabelStart() {
  4. var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "start");
  6. }
  7. //-->
  8. </script>
  9. </head>
  10.  
  11. <body onload="GotoLabelStart();">
  12.  
6. Another try:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/JavaScript">
  2. <!--
  3. window.onload=function(){
  4.  function GotoLabelStart() {
  5. var flashMovie=getFlashMovieObject("myFlashMovie");
  6.     flashMovie.TGotoStart("/", "start");
  7. }
  8. }
  9. //-->
  10. </script>
  11.  
7. Well, I tried ;-) Doesn't any one know a solution that actually works? The script needs to force the flash file to jump to a labeled frame onLoad.
Oct 10 '07 #1
1 8124
All these scripts I tried and won't work in Safari, Netscape, Opera and Firefox:

1.
Expand|Select|Wrap|Line Numbers
  1. <body onload="GotoLabelTerug();">
2.
Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. function addLoadEvent(func) {
  3.   var oldonload = window.onload;
  4.   if (typeof window.onload != 'function') {
  5.     window.onload = func;
  6.   } else {
  7.     window.onload = function() {
  8.       oldonload();
  9.       func();
  10.     }
  11.   }
  12. }
  13. addLoadEvent(function GotoLabelTerug()
  14. {
  15.     var flashMovie=getFlashMovieObject("myFlashMovie");
  16.     flashMovie.TGotoLabel("/", "terug");
  17. }
  18. );
  19. //-->
  20.  
3.
Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. window.onload=function GotoLabelTerug()
  3. {
  4.     var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "terug");
  6. }
  7. //-->
4.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function load()
  3. {
  4. var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "terug");
  6. }
  7. </script>
  8. </head>
  9. <body onload="load()">
5.
Expand|Select|Wrap|Line Numbers
  1. <!--
  2. function addEvent(obj, evType, fn){ 
  3.  if (obj.addEventListener){ 
  4.    obj.addEventListener(evType, fn, false); 
  5.    return true; 
  6.  } else if (obj.attachEvent){ 
  7.    var r = obj.attachEvent("on"+evType, fn); 
  8.    return r; 
  9.  } else { 
  10.    return false; 
  11.  } 
  12. }
  13. addEvent(window, 'load', GotoLabelTerug);
  14. //-->
6.
Expand|Select|Wrap|Line Numbers
  1. <!--
  2. function addEvent(obj, evType, fn){ 
  3.  if (obj.addEventListener){ 
  4.    obj.addEventListener(evType, fn, false); 
  5.    return true; 
  6.  } else if (obj.attachEvent){ 
  7.    var r = obj.attachEvent("on"+evType, fn); 
  8.    return r; 
  9.  } else { 
  10.    return false; 
  11.  } 
  12. }
  13. addEvent(document, 'load', GotoLabelTerug);
  14. //-->
7.
Expand|Select|Wrap|Line Numbers
  1. <!--window.onload=function(){load();}
  2. function load(){
  3.   movie=getFlashMovieObject();
  4.   movie.TGotoLabel("/", "terug"); 
  5. }//-->
Oct 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
4
by: David Virgil Hobbs | last post by:
My web host inserts banner ads into my html pages. The javascript in these banner ads interferes with the onload triggered javascript functions in my pages. Whether I trigger my javascript...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
11
by: Erwin Moller | last post by:
Hi group, I stumbled on something strange. I simplified the problem to this: A straightforward page with some JS: <span id="testid"> Hi
6
by: pronerd | last post by:
Hi, I am trying to dynamically set an event handler across frames. I have no problems setting properties across frames doing something like parent.ToolMenuFrame.location.href =...
20
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for...
5
by: lilOlMe | last post by:
Hi there! I'm developing some crazy Tab Control in .NET that uses JavaScript. A particular JavaScript method needs to be called during the window.onload event in order to initialize my Tab...
3
by: willyWEB66 | last post by:
Hi everyone, I'm having problem with the sequence of execution for xml.onload. It works fine if your not passing parameters to onload event but my code needs to pass parameter to its function. I'm...
2
by: WGW | last post by:
Hello all, I need another set of eyes cause it just isn't working, no matter how identical I make it. The initRotator function works when called by itself, but when adding another function, only the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.