Is it really necessary to serve my html through a HTTP server for mathjax to work?
I used these:
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=config=TeX-AMS-MML_HTMLorMML"></script>
...
...
...
...<div>\( A \over B^3 \)
...
...
There are no errors on the console, but I cannot seem to render the above equation.
Do I need to serve the HTML through an HTTP Server?
You are not using proper link to the latest version of the library:
<!DOCTYPE html>
<html>
<head>
<title>MathJax TeX Test Page</title>
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</head>
<body>
When \(a \ne 0\), there are two solutions to: \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
</body>
</html>
Use HTTPS
In this example, you can see that I am using HTTPS URL: https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML while you were using https://cdn.mathjax.org/....
The reason why you should prefer HTTPS is because MathJax is using some script to convert your Latex into SVG, it is just safer to download these scripts from a reliable source. Also, Javascript REPLs like JSFiddle, will not let you reference libraries through HTTP!
Related
I was trying to use the document.getElementbyId() but when I run the console it tells me it is not defined.
My index.html and index.js are in the same folder the source should be OK.
I'm using Cmd + Shift + P in Visual Studio Code and then choose "Run: without debbuging". The error message shows in the integrated console.
let word1 = "Alex";
let word2 = "Toko";
let example = `${word1} ${word2}`;
var doc = document.getElementById("test").innerText = example;
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<p id="test"> </p>
<script src="index.js"> </script>
</body>
</html>
The issue is the waqy you're running the code.
cmd+shift+P will run the index.js on it's own, and it won't know or care about the html.
Instead, open the html in your browser, and it should work.
The reason it won't work on vs code is that it runs the javascript file directly, and while the html links to the javascript, it won't work the other way around.
cmd+shift+P is used for server-side javascript, not client side. client side, you can just test in browser.
Just embarking in learning yet another language (JavaScript) and following instructions from a tutorial. I have node and Brackets (the editor) installed. The tutorial was requesting the following to be put in a file named
"app.js":
$('form').on('submit',function () {
var text = $('#message').val();
alert(text);
return false;
});
The problem I have is that the system immediately complains that "$" (two places) and "alert" are undefined.
The index.html file was originally requested to specify:
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="app.js"></script>
at the bottom (which caused the system to complain with an earlier simplified version about 'alert') but I replaced it with the following after visiting the code.jquery.com site:
<script
src="http://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script src="app.js"></script>
This solved the alert issue when the .js file was nothing more than a 'hello world', but now I have a "problem++" with the next version of the .js file shown above.
I suppose it could be something about the installation and/or paths; but I am at a loss figuring where that could be and how to fix it. Can any expert suggest something?
For the record: I am on a Windows 7 machine, using Chrome to display the html file.
Many thanks
Edit:
additional complete text of 'index.html' file:
<link rel="stylesheet" href="style.css">
<main>
<ol id="history">
<li>commander says: no offence, but you are a robot, aren't you?</li>
<li>roobie says: that is correct, sir</li>
<li>cookie says: hey doc, is that a male or a female? </li>
<li>robbie says: this information is meaningless</li>
</ol>
<form>
<input id="initials">
<input id="message">
<button>Send</button>
</form>
</main>
<script
src="http://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script src="app.js"></script>
did you add the jquery link twice?
Please remove all jquery links and do the following:
remove all previous jquery links.
Add this code snippet between your head tags.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
This should be a pretty easy one, but I haven't been able to find any solutions.
I need to include the following in my source code:
<script type="text/javascript" src="bower_components/MathJax/MathJax.js?config=AM_HTMLorMML-full"></script>
The ./config/am_htmlormml.js file is loaded by MathJax to render formulas written in ascii. The code runs and works fine, but I would prefer to use Bower. When I install MathJax via bower, I get:
<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
...
<script src="bower_components/MathJax/MathJax.js"></script>
...
<!-- endbower -->
<!-- endbuild -->
But I am unsure of how best to add ?config=AM_HTMLorMML-full1, or make sure the ./config/am_htmlormml.js file is loaded.
You can specify it in the config key when you configure MathJax. Note that my example uses a different config than yours (b/c this config worked with my example MathML).
<!doctype html>
<title>MathJax Bower Example</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
config: ["TeX-MML-AM_CHTML.js"],
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']]
},
});
</script>
<script async src="bower_components/MathJax/unpacked/MathJax.js"></script>
When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
I want to use coffeescript in a website, but something doesn't seem to be working. I have my coffeescript in a external file and it is linked to the html file. I have the coffeescript compiler also linked to the html file. What's wrong?
HTML:
<html>
<head>
<script type="text/javascript" src="coffee-script.js"></script>
<script src="jquery-1.10.2.min.js"></script>
<script type='text/coffeescript' src='Test.coffee'></script>
</head>
<body>
</body>
</html>
Coffeescript:
$->
random = (number) ->
console.log Math.ceil(Math.random() * number)
$("body").append(number)
random(2)
Try to compile your Coffeescript to Javascript before publication:
Once installed, you should have access to the coffee command, which
can execute scripts, compile .coffee files into .js, and provide an
interactive REPL.
Source: http://coffeescript.org/#usage
<html>
<head>
<script type="text/javascript">
document.write('f*** js');
document.write("f*** js!");
</script>
</head>
<body>
<script type="text/javascript">
document.write('f*** js');
document.write("f*** js!");
</script>
<div>f*** js</div>
</body>
</html>
I want use xpath to catch all lable object in the html page above...
In [1]: import lxml.html as H
In [2]: f = open("test.html","r")
In [3]: c = f.read()
In [4]: doc = H.document_fromstring(c)
In [5]: doc.xpath('//a')
Out[5]: [<Element a at a01d17c>]
In [6]: a = doc.xpath('//a')[0]
In [7]: a.getparent()
Out[7]: <Element div at a01d41c>
I only get one don't generate by js~
but firefox xpath checker can find all lable!?
http://i.stack.imgur.com/0hSug.png
how to do that??? thx~!
<html>
<head>
</head>
<body>
<script language="javascript">
function over(){
a.innerHTML="mouse me"
}
function out(){
a.innerHTML="<a href='http://www.google.com'>google</a>"
}
</script>
<body><li id="a"onmouseover="over()" onmouseout="out()">mouse me</li>
</body>
</html>
Not a clue about javascript-aware parser in python but you can use ANTLR to do the job. The idea is not mine so I'm leaving you the link.
It's actually quite cool because you can optimize your parser to selectively choose what instruction needs to be parsed (and executed).
In Java there is Cobra. I don't know any Javascript-aware HTML parser for Python.
Searching google for "javascript standalone runtime", I found jslibs: a "standalone JavaScript development runtime environment for using JavaScript as a general-purpose scripting language", based on "SpiderMonkey library that is Gecko's JavaScript engine".
Sounds great! I haven't tested yet, but it seems like this will allow you to run the javascript code you find in the page. I don't know how much it will be tricky, though..