Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
All of the answers to this question so far as I can see are confusing... can someone give me a detailed way to make EXE apps with HTML?
No. In the strict sense you can't. HTML was mainly invented to design and exchange documents written for a browser (and CSS provides layout information for such a document).
Although, that is not the case anymore. There are many possibilities, where HTML and CSS is used outside of the browser (e.g Gnome Shell is developed with the help of CSS and Javascript or think of Modern UI apps for Windows 8).
So if you consider Windows 8, there is the possibility of creating an app outside of the browser; but technically it is not an .exe It is not an executable.
Another possibility is to make use of the WebBrowser Class, which allows you to write an .exe which makes use of your HTML and CSS.
So there are ways to stuff HTML into an executable, but you can not make it executable by itself, since it is a document/markup language and not a programming language and can not be converted to running code.
There are several possible directions here, and I can't be sure what you really want.
If you have a static HTML site, you can load it into any web browser from a local disk. This is exactly how "Save as complete web page" functionality works in all major browsers. You can even put this on a CD/DVD and cause Window's autorun feature to automatically load it in a web browser. This method (or some variation) is probably what you want.
If it is a non-trivial web app, then it is already an executable, albeit on the server, not the client. (I assume this is not the case). This cannot easily be converted to a desktop app, for reasons obvious to anyone with the skill to do so.
If you want to make the UI of an application via HTML/CSS, that's a whole different story. Its a means to an end; the app is the actual product. But this involves making a real exe: still no cheating.
So, okay. Despite the "no-cheating" claim above, it is possible to build an application using Javascript as the programming language. In this case it is an "executable", but not really an .exe: it's a .js file. You would need a standalone Javascript interpreter for this. But this doesn't necessarily involve any HTML or CSS at all: Javascript is a programming language in its own right, just like the ones other apps are build with.
So no, HTML is not put into executables strictly for viewing pleasure. Its technically possible, but also infeasible: far better solutions already exist. E.g. how do you justify choosing which browser to integrate? Will you force every user to use your exe browser instead of their favorite?
HTML is a language similar to XML - it is interpreted, not compiled. Thus, you cannot make MS Windows executable files (*.exe) with HTML.
This is a common misconception. HTML is a markup language, which means it must be interpreted by an engine that can display the actual visuals that HTML encodes.
One cannot simply compile HTML, CSS, and JavaScript into an executable file. These are all merely scripting, styling, and markup languages that must be interpreted by an engine (which in many cases is executable).
In Visual Studio 2010 you can create a simple window with a WebView element, and you can populate this element with custom HTML, and inject JS, and so forth. This is described more in depth here: http://blogs.msdn.com/b/wsdevsol/archive/2012/10/18/nine-things-you-need-to-know-about-webview.aspx
Finally, you may be thinking about Visual Studio 2013, which allows you to use JavaScript.
JavaScript is a first-class language in Visual Studio 2013. You can
use most or all of the standard editing aids (code snippets,
IntelliSense, and so on) when you write JavaScript code in the Visual
Studio IDE. You can write JavaScript code for Windows Store apps and
Web apps in Visual Studio.
However, keep in mind that all of your JavaScript gets compiled down into the CLR (Common Language Runtime) which can be read about more here: http://en.wikipedia.org/wiki/Common_Language_Runtime
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I've read a lot of things about interpretation, compilation, just-in-time compilation, etc. But I haven't found a clear explanation about why JS was created as an interpreted language and why there is still no ability to compile js code.
I have some thoughts, but I'm not sure about any of them:
If the browser could execute (or just pass to OS) a binary code it would be a big vulnerability because any command could be injected into a binary code (e.g. delete all files from the file system). If it's true is it possible to teach the browser to validate somehow a binary code? And it's not a problem for a back-end side. Then, why NodeJS can't execute compiled JS (the same for PHP, Python, why they are interpreted)?
Optimization isn't possible for binary code. Is it really true? Is optimized interpreted js faster than compiled (to binary) js?
Different CPUs (architectures) need different binary codes. That means it's impossible to generate a universal binary code for any client. That's why WebAssembly modules use some intermediate code? And again why to not use compiled code for a back-end?
If anyone could explain some of the above or any other reasons I would be very grateful.
Let's first say that unless you were in the design discussions for Javascript in its early days, none of us actually "know" why. The best we can do is try to infer why certain choices might have been made given the objectives they had and the choices they had.
If you look at the requirements for the original design of Javascript in web pages, you see things like this:
Must run on lots of platforms.
Must be easily embeddable in HTML pages.
Must be simple to program.
Is not initially an environment that feels the need to maximize execution performance.
Not Java.
Let's look at these...
About #1, OK, run on lots of platforms means it cannot be compiled to native machine code - period. It could be compiled to a universal byte code like Java or webAssembly, but read on about the other requirements.
About #2, it wants to be embeddable in web pages so you can do things like:
<div onclick='alert("hi")'>Click me</div>
Then, it's pretty hard to have code that is compiled in advance fit in there. You'd probably have to compile your whole web page. That creates an entirely new paradigm and browser (that expects pre-compiled code and HTML). While the world could have eventually gone there, that certainly wasn't an easy way to go (requiring a redo of the browser).
About #3, "simple to program", it's generally believed that interpreted "scripts" are simpler for people to start with than languages that need a programming environment and compiler set up and some build tools. It's faster and simpler to do simple things.
About #4, "performance". In the early days of Javascript, it was an auxiliary language to help add some client-side logic to web pages. The initial target was far simpler than what Javascript is being used for today. I rather doubt it was envisioned that a pre-compiled language was needed for what its initial target was. So, keep it simple and go with the simpler way of reaching your target.
About #5: "not Java". Java was a known tool of the day. But, Java was not super simple, required pre-compiling, had IP encumbrances, etc... So, Javascript was born to be something that was familiar to both C and Java developers, but was far simpler for someone new to pick up. Easy to do simple things.
As for environments like nodejs, they could more practically have a pre-compile step, but the early designers of nodejs decided to use the open source V8 Javascript engine rather than make their own Javascript engine. Plus, in a server world, your code is generally loaded once at server startup where V8 compiles it to a combination of native code and byte code anyway so requiring developers to pre-compile it doesn't necessarily buy you a lot anyway. This is where it matters that Javascript is now actually compiled, it's just compiled upon loading rather than requiring pre-compiling by the developer.
And, nowadays, if you want the benefits of type checking in a pre-compile step, you can use TypeScript and precompile that to Javascript.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to write a web crawler that can interpret JavaScript. Basically its a program in Java or PHP that takes a URL as input and outputs the DOM tree which is similar to the output in Firebug HTML window. The best example is Kayak.com where you can not see the resulting DOM displayed on the browser when you 'view source' but can save the resulting HTML though Firebug.
How would I go about doing this? What tools exist that would help me?
Ruby's Capybara is an integration test library, but it can also be used to write stand-alone web-crawlers. Given that it uses backends like Selenium or headless WebKit, it interprets javascript out-of-the-box:
require 'capybara/dsl'
require 'capybara-webkit'
include Capybara::DSL
Capybara.current_driver = :webkit
Capybara.app_host = "http://www.google.com"
page.visit("/")
puts(page.html)
I've been using HtmlUnit (Java). This was originally designed for unit testing pages. It's not perfect javascript, but it hasn't failed me in my limited usage. According to the site, it can run the following JS frameworks to a reasonable degree:
jQuery 1.2.6
MochiKit 1.4.1
GWT 2.0.0
Sarissa 0.9.9.3
MooTools 1.2.1
Prototype 1.6.0
Ext JS 2.2
Dojo 1.0.2
YUI 2.3.0
You are more likely to have success in Java than in PHP. There is a pre-existing Javascript interpreter for Java called Rhino. It's a reference implementation, and well-documented.
Rhino is used in lots of existing Java apps to provide Javascript scripting ability within the app. I have also heard of it used to assist with performing automated tests in Javascript.
I also know that Java includes code that can parse and render HTML, though someone who knows more about Java than me can probably advise more on that. I am not denying it would be very difficult to achieve something like this; you'd essentially be re-implementing a lot of what a browser does.
You could use Mozilla's rendering engine Gecko:
https://developer.mozilla.org/en/Gecko
Give a look here: http://snippets.scrapy.org/snippets/22/
it's a python screen scraping and web crawling framework used with webdrivers that open a page, render all the things you need and gives you the possibilities to "capture" anything you want in the page via
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm a C# developer, and use XAML for user interfaces. Lately I've been wondering something regarding HTML5+JavaScript development (used in Universal Windows App development, as well as for websites). Javascript is compiled and executed at run-time on the client device. So any user can go into the folder where they're stored on computer, and see all the code in it, right?
There is no unreadable alternative for js and html5. That's why so many websites are so slow in adopting html5 video and replacing adobe flash.
But if your entire application is client side and you worry about your code being stolen you're doing something wrong. Almost any application requires serverside code that isn't accessible.
And it doesn't matter anyway, who cares about some js that makes a div draggable or moves some html around.
I dont think readable javascript code is of any value...what matters is the server side code like php or ASP which really matters in the security of the websites
And even if the developer didnt want the user to read the javascript framework.. what option does he/she have to prevent it..?none!
The client side code is indeed visible by the client. If something is available client side, then you won't need a round trip to the server to get it.
For example you could imagine a simple calculator application. You could write it client-side, in Javascript, the app can ouptut the calculations immediately. Or you could write it server-side (in wathever language you want), which means you need to ask the server for the calculation (with an ajax request probably), and wait for it to respond.
Also some things doesn't make sense on the server-side. Pretty much any action that changes the DOM, which only exists client-side, in the browser.
I wrote about this on my blog a while back, see Protecting Your Code,
as an addendum to my free ebook, Programming Windows Store Apps with HTML, CSS, and JavaScript, 2nd Edition.
The short of it is that JS code it not protected, though you can make things a little more difficult with minification/uglification like many website authors do. You can also take steps by putting some of the code you care about into Windows Runtime Components written in C++ (C# can be decompiled). The only really secure solution is to have code on a server, and draw from that in an app which of course doesn't work for all cases, but is an option.
Note that some of my comments in that blog from 3 years ago might be a little dated. I believe that current Windows Store policy now allows you to load code from a remote server at run time.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
How does generating HTML/CSS directly in HTML/CSS files, compare with generating HTML/CSS in Javascript?
I have written some code in HTML and CSS, but feel I have much more control over what I am doing when writing Javascript, as it is a fully fledged programming language. Then I have one type of file for the system and can control the structure of the system much better etc.
It has therefore become tempting to simply write everything in Javascript directly.
But what are the downsides of writing HTML/CSS directly in Javascript?
1- People who disable javascript can't see your content
2- It takes longer to render everything, since javascript is ran after DOM loads.
3- Search engines can't see what content is on you page
JavaScript is a client-side language — therefore, writing HTML with JS onto a blank page (I guess that is what you are referring to) will be performed on the client side. This makes you lose some degree of control over how HTML and CSS are written to the page, e.g. when the end-user does not have JS-enabled. Most search engine bots also do not have JS enabled, which means your page will be blind to search engines in general.
However, serving HTML and CSS files instead of writing them using JS will allow you to serve files from the server-side. You can insert information into HTML and CSS files from the server side, e.g. using PHP, before they are sent to the user.
In addition, by using JS, you will be losing this control unless you bridge that gap using AJAX.
Before thinking of doing this you need to ask Why are you willing to do it? If it is for practicing and/or developing your JS skills, I understand but it has little practical use.
Javascript is a programming language. Although it does have many applications (including in AJAX), it gives you the ability to modify client-side code dynamically. So, the standard practice is to write static HTML/CSS files as HTML/CSS respectively and then when you need to trigger something dynamically to modify HTML (or text) or styling (CSS) of the elements, you can use Javascript.
As someone else pointed out, search engines / spiders can only access server-sided pages and JS works on client-side so none of your content would be "crawlable" by the search engine spiders.
Even though, CSS or rather CSS3 does give you some limited ability to perform dynamically alter client-side styling, for example the :hover selector or CSS Animations, for more advanced applications, Javascript is used.
It is crucial to think by the way, on devices where Javascript is disabled, none of your site pages would load if your site was rendering all the HTML/CSS in Js, purely.
Therefore, it is best to use HTML/CSS for static text/code/styling and JS for dynamically updating your page.
Hope it helps!
No current answer adequately address both the advantages and disadvantages to writing HTML or CSS through JavaScript, so I will attempt to address both sides of the issue.
Advantages:
JavaScript is reusable. Elements common to many pages can be shared, and as JavaScript is a language, these common elements can be manipulated to suit the requirements of the page.
JavaScript can be consumed by external sites, allowing a developer to create dynamic content that can be compiled and rendered externally.
JavaScript can handle robust data through JSON objects, which allows for manipulation of data on the client while writing the visual markup.
JavaScript developers have created many frameworks, such as jQuery, that help avoid re-inventing the wheel.
Disadvantages:
JavaScript must be executed by the client, which can take time and impact the performance of your application.
JavaScript cannot be crawled by search engines, which will negatively impact your search engine optimization strategy.
While rare, JavaScript cannot be used by browsers that do not support it. Users attempting to access your application will see only the HTML markup if they cannot execute JavaScript.
Incorrect use of JavaScript opens your application to malicious threats, such as cross-site scripting, where static HTML may have never introduced the threat.
As mentioned by Djizeus, frameworks exist that use JavaScript extensively in developing web applications. AngularJS is an example of a framework that aims to assist in creating single-page applications through JavaScript (though static HTML and CSS is also utilized).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have made a website wich uses HTML, PHP, Javascript and Ajax and is working based on MySQL database. My question is if there is a way to make this whole website run as a program with no need to open browser. Like outlook or filezilla where both are programs involving servers and web but they need no browser.
I dont expect you to give me a step by step guide but only to tell me if this is possible.
You can use a headless browser, like Zombie.js that will allow you to browse your app programatically without employing a graphical browser. It supports AJAX call and everything.
This is usually done for testing whether the web app works as expected.
Anyway, if you want your app to be used without a browser, best you can do is transforming it into a console app.
If you want the app to be used from both the web and console, or other environment, you can make it work RESTful, and develop 2 interface layers: web, console or whatever you need, all of them consuming the same services so the functionality will be the same.
Sure,
you can develop a java application which uses for example JavaFX on the presentationlayer and there you'll have a class called WebView within you can display your HTML pages.
But you need to run your PHP Application on a WebServer which renders the page on runtime / calltime and serves the data. On this server you also run your MySQL Server.
You could try HTA (HTML Applications). Note that its a product of Microsoft and I have tried this only in Windows.
It acts as an stand-alone application and you can do that just by changing the extension from .html to .hta for your main file.
From Wiki:
An HTML Application (HTA) is a Microsoft Windows program whose source
code consists of HTML, Dynamic HTML, and one or more scripting
languages supported by Internet Explorer, such as VBScript or JScript.
The HTML is used to generate the user interface, and the scripting
language is used for the program logic. An HTA executes without the
constraints of the internet browser security model; in fact, it
executes as a "fully trusted" application.
The usual file extension of an HTA is .hta.
More Links:
http://en.wikipedia.org/wiki/HTML_Application
http://www.htmlgoodies.com/beyond/reference/article.php/3472841