0

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: {
      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?

0

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.