According to Chinese custom, we are still celebrating the New Year before the fifteenth day of the first lunar month. Here I would like to wish your friends in the garden a happy new year. Copy code The code is as follows:<html> <title>DEMO</title> <head> <script type="text/javascript" src="swfobject_source.js"></script> <script type="text/javascript"> var so = new SWFObject("http://www.pec365.com/Flash/20071113.swf", "mymovie", "304", "367", "7", "#FFFFFF"); so.write("flashcontent"); </script> </head> <body> <form id="Form1"> <div id="flashcontent"> <a href="http://www.adobe.com/go/getflashplayer"> <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" border="0" /> </a> </div> </form> </body> </html> If you want to briefly understand the meaning of each parameter in SWFObject(), please refer to the documentation. I will not repeat it here. I strongly recommend that you copy the code in "V1.5 Usage Example" into Notepad, and click SWFObject V1.5 to download the required source file of the V1.5 framework. After decompression, find the swfobject_source.js (uncompressed version, the compressed version file name is swfobject.js) file, rename the Notepad file to demo.html and put it in the same folder as the swfobject_source.js file, and then run it in any browser such as IE6/IE7, fox, opera, safari, navigator, chrome, etc. to see the results. If you followed my advice, you should see this image on the page. ![]() If you happen to be using VS 2003/2005/2008 series IDE for development, then I think there is no need to teach you how to debug JavaScript code. You can put a debugger above var so = ..., and then debug and trace in. Keep pressing F11 until you trace to the inside of the swfobject_source.js file through the so.write() method. You will find that the actual parameter "flashcontent" passed to so.write(elementId) is always null when document.getElementById("flashcontent") is used. Why is this? Did you find the problem? Haha, if you are still a novice who doesn't know much about JavaScript, you will be confused like I was at that time. After many times of debugging and code modification, I firmly believe that there is no error in the JS code I wrote. Could it be that there is a problem with the externally loaded swfobject_source.js file? If there is a problem, then what is the problem? At that time, I tried to find a solution to the error. I modified the above code into the following example: Copy code The code is as follows:<html> <title>DEMO</title> <head> <script type="text/javascript"> // Executing an anonymous function is no different from executing a normal function (function() { var flash = document.getElementById("flashcontent"); var msg = null; window.onload = function() { if ( flash ) { msg = 'The element does exist.'; flash.innerHTML = msg; } else { msg = 'The element does not exist'; window.alert( msg ); } }; })(); </script> </head> <body> <form id="Form1"> <div id="flashcontent"> <a href="http://www.adobe.com/go/getflashplayer"> <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" _fcksavedurl=""http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"" alt="Get Adobe Flash player" border="0" /> </a> </div> </form> </body> </html> If you execute the above code, you will find that the picture is still displayed on the page. ![]() If you read this, you will definitely experience my frustration at that time. After a short rest, I cleared my mind and looked back, and found that the essence of the problem lies in the "loading of HTML DOM". In a page, the JS scripts in the page head (between <head></head>) and the JS files loaded from external files will be executed before the HTML DOM is actually constructed. Therefore, scripts executed in these two places cannot access the DOM that does not exist yet. You should know the real reason. That is, during the execution of the JS code in Example 1.1, <div id="flashcontent">……</div> was accessed before it was constructed. Well, there is one last step that you need to do yourself, which is to simply modify the above code and take an inelegant method to solve the problem of "HTML DOM loading". Which method is it? I think you may have guessed it. Yes, it is the following method: Copy code The code is as follows:<html> <title>DEMO</title> <head> <script type="text/javascript" src="swfobject_source.js"></script> _fcksavedurl=""swfobject_source.js"></script>" </head> <body> <form id="Form1"> <div id="flashcontent"> <a href="http://www.adobe.com/go/getflashplayer"> <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" border="0" /> </a> </div> </form> <script type="text/javascript"> var so = new SWFObject("http://www.pec365.com/Flash/20071113.swf", "mymovie", "304", "367", "7", "#FFFFFF"); so.write("flashcontent"); </script> </body> </html> The thousands of words above are just describing how many detours I took, the troubles I encountered in the process of solving problems, how I got out of the troubles, used the knowledge I learned, and learned again. Although it is a bit cumbersome, have you gained something like me? |
<<: Implementation of CSS border length control function
>>: React Router 5.1.0 uses useHistory to implement page jump navigation
Nginx hides version number In a production enviro...
Preface The Linux system is controlled by the sys...
Table of contents 1. Introduction 2. Why do we ne...
1: Tag selector The tag selector is used for all ...
Table of contents Preface 1. Style penetration 1....
Table of contents 1. Environment variable $PATH: ...
Today I looked at some things related to data bac...
Preface When we use query statements, we often ne...
1. Problem Forgot password for mysql5.7 under lin...
I didn't intend to write this blog, but durin...
Table of contents First of all, you need to know ...
Table of contents Preface LED Trigger Start explo...
Table of contents Function definition method Func...
This article shares the specific code for JavaScr...
Preface Before we begin, we should briefly unders...