Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add javascript in the head of a HTML knitr document?

I use the Rmd version of knitr because it is less verbose than Rhtml. I am currently doing

<script src="http://d3js.org/d3.v2.min.js"></script>

in the body of the Rmd document, but this should be in the head of the downstream HTML document that gets generated by markdownToHTML. Is it possible?

like image 396
nachocab Avatar asked Jan 13 '13 21:01

nachocab


People also ask

Can you put JavaScript in HTML head?

You can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.

How do I link a JavaScript head in HTML?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

Can I put JavaScript in markdown?

Markdown JavaScript (mdjs) is a format that allows you to use JavaScript with Markdown, to create interactive demos. It does so by "annotating" JavaScript that should be executed in Markdown.

Should I link JavaScript in head or body?

The best practice is to put JavaScript <script> tags just before the closing </body> tag rather than in the <head> section of your HTML. The reason for this is that HTML loads from top to bottom. The head loads first, then the body, and then everything inside the body.


1 Answers

You can place the script tags inside your tags. then use the tags like this:

<SCRIPT language="JavaScript" SRC="jxt1.js"></SCRIPT>

you where missing the laguage type there, so the code can understand on which language is he going to "read"

look here (http://www.pageresource.com/jscript/jxtern.htm) for more detailed information

like image 116
Ricardo Alves Avatar answered Oct 03 '22 03:10

Ricardo Alves