0

I am currently working in HTML and JavaScript. I am Beginner. I want to open a javascript file in the onclick event of the button which is in my html file. is there any method to do this. kindly help me.

thanks in advance.

3
  • 2
    What do you mean open a javascript file, what exactly is in this file and why would you need it to be opened? Commented Aug 26, 2011 at 9:18
  • What do you mean by open? You want to show the sourcecode within the browser? You want to download the sourcecode? Commented Aug 26, 2011 at 9:19
  • @Dray: Maybe you simply need to call some javascript function when button clicked? Commented Aug 26, 2011 at 10:56

1 Answer 1

3

It think you mean it "Load" instead of open

You can 'Load' JS file dynamically using following code

  var fileref = document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", yourfilename)
Sign up to request clarification or add additional context in comments.

1 Comment

Can be important in some cases add an attribute "charset".

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.