The interesting script tag uses the getAttribute method from the script.

Source: Internet
Author: User
Tags ojs

Introduce external objects and PASS Parameters on the webpage. In general, the tags used are iframe and embed (for flash). However, neither of these labels can set parameters like xml, you can only append the query string after the url to pass the value. Htc is quite good, but it does not have browser compatibility. If you want to, you will not consider it.
The script tag can be used to load an external js file to the page, regardless of whether the file is in the same domain or not. This cross-domain feature is unique. In general, we only use js files as part of public code, and integrate some public functions and classes here. In another way, we think of the script tag as a large visual component. It is interesting to pass in parameters and adjust the layout according to parameters.
For example, "<script width = 300 height = 200 filePath =" http://mp3.baidu.com/abc.mp3 "src = player. js> </script> "is this method intuitive and practical? You will ask, How does player. js get the parameters in the script tag? In fact, this is very simple. You only need to find the last script element in player. js, which is the current element. Then you can use the getAttribute method to retrieve all the parameters you want.
<Body> </body>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
In addition to the Code, does a script tag think about using it to store data? The main purpose of this operation is to implement cross-origin restrictions.
You can use strings to store text. However, this method is not intuitive and requires special characters to be processed. For example:
Str = "aaaa"
Str + = "bbbb"
Or
Str = "aaaa \
Bbbb"
We can use functions to display the source code, display the remarks in the source code, and cleverly place the data in the remarks so that we do not need to comply with the js syntax specifications.
<Body> </body>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
I have an application to share with you.
Because of the xp patch, a virtual box is added to all the flash files on the websites of dajiang north and south overnight. You need to click it to activate it. When you hate your teeth, you have to come up with the corresponding method. below is the method for xinlang to insert flash:
-----------------------------------------------------
<Script type = "text/javascript" src = "http://image2.sina.com.cn/home/sinaflash.js"> </script>
<Script>
Var objFlash = new sinaFlash ("abc.swf", "", "100", "100", "7", "", false, "high ");
ObjFlash. addParam ("wmode", "opaque ");
ObjFlash. write ("flashcontent_1D194BAF55E2 ");
</Script>
-----------------------------------------------------
If the script tag is used properly, it can be simplified:
-----------------------------------------------------
<Script src = "swf. js" movie = "abc.swf" width = "100" height = "100" wmode = "opaque"> </script>
-----------------------------------------------------
A word is enough
The content of the swf. js file is as follows:
-----------------------------------------------------
Var ol, oJs, flaID, sMovie
Ol = document. getElementsByTagName ("script ")
OJs = ol [ol. length-1]
FlaID = oJs. getAttribute ("flaID") | ""
SMovie = oJs. getAttribute ("movie ")
If (sMovie. slice (0, 1) = "{" & sMovie. slice (-1) = "}")
SMovie = eval (sMovie. slice (1,-1 ))
L = "<object classid = 'clsid: D27CDB6E-AE6D-11cf-96B8-444553540000 'id ='" + flaID + "'width = '" + (oJs. getAttribute ("width") | "100%") + "'height = '" + (oJs. getAttribute ("height") | "100%") + "'> \
<Param name = movie value = '"+ sMovie +"'/> \
<Param name = wmode value = '"+ (oJs. getAttribute (" wmode ") |" window ") +"'/> \
<Param name = allowscriptaccess value = 'always'/> \
<Embed id = '"+ flaID +" 'name =' "+ flaID +" 'allowscriptaccess = always wmode = transparent src = '"+ sMovie +" 'width = 120% height = 100% type = 'application/x-shockwave-flash'> </embed> \
</Object>"
Document. write (l)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.