Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

How do I include javascript in the head of every page?

edited November 2010 in Vanilla 2.0 - 2.8
In the <<head>> of every page, I simply want to include something like the line:

<<script type="text/javascript" src="http://mysite.com/MathJax.js">> <</script>>

(It's a script for formatting mathematics. Those double angled brackets should be just singles, but when I entered them in as such, nothing showed.)

Let's say I want it just before the line with the closing <</head>>.

How can I do this?

Thanks.


Comments

  • Options
    LincLinc Detroit Admin
    edited November 2010
    With a simple plugin.

    Make a folder called 'AddToHeader' under plugins.
    Make a default.php file there and paste this code into it.
    Make a folder in that one called 'js' and put your Javascript file in it (whatever.js).

    <?php if (!defined('APPLICATION')) exit(); $PluginInfo['AddToHeader'] = array( 'Name' => 'AddToHeader', 'Description' => 'Adds stuff to the header of every Vanilla page.', 'Version' => '1.0', 'Author' => "You", 'AuthorEmail' => 'whatever@gmail.com', 'License' => 'GNU GPLv2' ); class AddToHeader extends Gdn_Plugin { public function Base_Render_Before(&$Sender) { // Add a Javascript file // Put Javascript files in 'js' folder under AddToHeader folder $Sender->AddJsFile('whatever.js'); // Example to add CSS files to entire site (uncomment to use) // Put CSS files in 'design' folder under AddToHeader folder //$Sender->AddCssFile('whatever.css'); } }
    Upload the folder and then enable it in the Dashboard.
  • Options
    edited March 2011
    Hi,

    Just noticed this post on MathJax, and I wanted to add that MathJax is now available through a CDN at http://cdn.mathjax.org/mathjax/latest/MathJax.js The CDN removes the need to download and install the MathJax software and makes sure that you are always working with the latest version. Details on how to get started with the CDN can be found on http://www.mathjax.org/docs/1.1/start.html

    MathJax is an open source JavaScript engine that renders mathematics on webpages. It offers crisp math display, nicely integrated into the surrounding text with matching sizes, margins, and baselines. MathJax allows you to copy math to the clipboard so that you can use it in calculation applications, and it works together with math accessibility software to help blind, poor vision, dyslexic, and learning-disabled readers.

    It's really easy to use MathJax with your webpage or blog. All you need to include is a single line of code in the heading of your webpage, and then you can use equations in either LaTeX or MathML. Have a look at http://www.mathjax.org to learn more.
Sign In or Register to comment.