Interesting script tags with getattribute method from the Scripting bar _javascript tips

Source: Internet
Author: User
Tags script tag ojs

The

introduces external objects and passes arguments to the Web page, and everyone has this experience. In general, the labels used are IFRAME and embed (for Flash), but neither of these tags can set parameters like XML, and can only pass values by appending the query string to the URL address. HTC is pretty good, but there is no browser compatibility, you want to think about it.  
     Use the script tag to load an external JS file into the page, and this cross-domain feature can be said to be unique, regardless of whether the file is in the same field. In general, we just use the JS file as part of the common code, where we integrate some common functions and classes. In other words, it is interesting to think of the script label as a large visual component, passing parameters to it and adjusting it to different layouts based on parameters.  
     For example, "<script width=300 height=200 filepath=" http:// Mp3.baidu.com/abc.mp3 " src=player.js></script>", such writing is not very intuitive, but also has practical? People will ask, player.js how to take the parameters in the script tag? In fact, this is very simple, just find the last script element in the Player.js, this is the current element, and then use the GetAttribute method, want to take the number of parameters can be.  

<body> </body> <script> </script> <script filepath= "abc.html" > var scripts=doc Ument.getelementsbytagname ("script"); var self=scripts[scripts.length-1]; document.write (Self.getattribute ("filepath")); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Does the script label ever want to use him to store data in addition to the code? This is done primarily to achieve cross-domain constraints.
You can store text in a string, but this is not intuitive and requires special characters to be processed, such as:
Str= "AAAA"
str+= "BBBB"
Or
Str= "Aaaa\
BBBB "
We can use the function to display the source code, and can display the characteristics of the notes in the source code, the data cleverly placed in the notes, so you can not adhere to the JS syntax specifications.
<body> </body> <script> data=function () {/* Test data is placed here. Whatever data "'" or "" "" "these special characters can be */} Alert ((data+ ""). Slice (13,-4)) </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

There is an application that you can share with me.
Because of the XP patch, overnight to the site of the Flash all add a virtual box, need to click to activate. Everyone in hate toothache, had to come up with the corresponding method, the following is the Sina Insert Flash Method:
-----------------------------------------------------
<script type= "Text/javascript" src= "Http://image2.sina.com.cn/home/sinaflash.js" ></script>
<script>
var objflash = new Sinaflash ("abc.swf", "", "M", "M", "7", "", False, "high");
Objflash.addparam ("wmode", "opaque");
Objflash.write ("Flashcontent_1d194baf55e2");
</script>
-----------------------------------------------------
If you use the script label, you can simplify to:
-----------------------------------------------------
<script src= "Swf.js" movie= "abc.swf" width= "a" height= "wmode=" ></script>
-----------------------------------------------------
A word is enough.
The following is the contents of the Swf.js file:
-----------------------------------------------------
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+ height=100% type= ' Application/x-shockwave-flash ' ></embed>\
</object> "
document.write (L)

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.