Call a python function within a html file

You’ll need to use a web framework to route the requests to Python, as you can’t do that with just HTML. Flask is one simple framework: server.py: from flask import Flask, render_template app = Flask(__name__) @app.route(“https://stackoverflow.com/”) def index(): return render_template(‘template.html’) @app.route(“https://stackoverflow.com/my-link/”) def my_link(): print ‘I got clicked!’ return ‘Click.’ if __name__ == ‘__main__’: app.run(debug=True) templates/template.html: … Read more

Parse html using C

You want to use HTML tidy to do this. The Lib curl page has some source code to get you going. Documents traversing the dom tree. You don’t need an xml parser. Doesn’t fail on badly formated html. http://curl.haxx.se/libcurl/c/htmltidy.html

Can I nest form tags in other form tags?

No, nested forms are forbidden. This is expressed in the HTML 4.01 DTDs as: <!ELEMENT FORM – – (%block;|SCRIPT)+ -(FORM) — interactive form –> — http://www.w3.org/TR/html4/interact/forms.html#h-17.3 This means A FORM has a mandatory start tag, mandatory end tag and can contain anything in %block or SCRIPT, except other FORMs. XML DTDs aren’t as expressive as … Read more

HTML5: Detecting if you’re on mobile or pc with javascript? [duplicate]

I was looking into this a few years back. In short, you can’t do this with 100% reliability. There seem to be 2 approaches commonly used to provide a ‘best-guess’: 1. User Agent Detection This is where you check what the client is claiming to be. e.g. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { // is mobile.. … Read more

Are void elements and empty elements the same?

The term “empty element” comes from SGML, on which HTML standards prior to HTML5 were based, and where the EMPTY keyword is used to represent elements with an empty content model. Here’s what the HTML 4 spec says: The allowed content for an element is called its content model. Element types that are designed to … Read more

Access webcam without Flash

At the moment of writing this the best solution is WebRTC. It is supported in Chrome, Mozilla and Opera, but still unavaialble in Internet Explorer and Safari. Minimalistic demo. Index.html <!DOCTYPE html> <head> </head> <body> <video></video> <script src=”https://stackoverflow.com/questions/9644612/webcam.js”></script> </body> webcam.js (function () { navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia); navigator.getMedia( // constraints {video:true, audio:false}, … Read more

Get drop down value

If your dropdown is something like this: <select id=”thedropdown”> <option value=”1″>one</option> <option value=”2″>two</option> </select> Then you would use something like: var a = document.getElementById(“thedropdown”); alert(a.options[a.selectedIndex].value); But a library like jQuery simplifies things: alert($(‘#thedropdown’).val());