I want to convert some code twitter gave me to a separate .js file. This is what they gave me.
document.write("<script>
new TWTR.Widget({
version: 2,
type: 'search',
search: '@BigNotch',
interval: 6000,
title: 'Follow Me On Twitter',
subject: 'BigNotch',
width: 180,
height: 300,
theme: {
shell: {
开发者_C百科 background: '#17d1ff',
color: '#ff8fda'
},
tweets: {
background: '#ededed',
color: '#383838',
links: '#ff8aed'
}
},
features: {
scrollbar: false,
loop: true,
live: true,
hashtags: true,
timestamp: true,
avatars: true,
toptweets: true,
behavior: 'default'
}
}).render().start();
</script>
I created a separate .js file and just copied what was between the
<script></script>
and pasted it into the .js file. Is this the correct way to to this?
Yes, moving that to an external file is all that you need to do. It will be the same as if you had written it inline.
Note that because the script is using document.write
, you'll want to reference to external file in the same place you would have referenced the in-line script (i.e. its rendering is dependent on its position in the document).
Yes. But after separating your js code into external files, you should be aware of correct order of including them.
e.g.
if you have some frameworks libraries (jQuery, Prototype, etc) and other files that use them. you should put frameworks first, and after put all other js files
精彩评论