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 5 years ago.
Improve this question
So I have been wondering how can I manipulate DOM in languages other than Javascript and PHP. I can always use Javascript and PHP in one HTML file with other HTML and CSS code.
Similarly, in Javascript there are multiple methods such as document.getElemenyById() etc. In PHP, basically it is a hypertext pre-processor and thus it automatically renders HTML through the server which again can be used for DOM Manipulation.
What about other languages? Can we use them to build the web? Or specifically, do things like HTML and CSS Manipulation. Let's say for example, Python or C#. How can I use them like JS and PHP?
There are two stages of "working" with DOM.
The first stage is the server render. When PHP engine receives template (mix of HTML, PHP) plus data and outputs valid HTML to a browser. In this stage, you can build HTML that will be parsed by a browser to DOM tree. You don't work with DOM, but rather with a plain text of your template.
The second stage is the Javascript evaluation. A browser parses and runs JS, and this JS has access to DOM tree.
The first stage can be done in any language that runs on a server. You can use c# templates, python templates, go templates, even javascript. All template engines just proceed template (text) and data and give text output which can be valid HTML.
The second stage works only with JS because browsers work with JS only. There were some attempts to bring other languages to a frontend (like Dart), and all failed. But you have some options. There are many compilers for existing languages that can target JS. For example, clojruescript for clojure, bucklescript for ocaml, gopherjs for go and others. Also, there are bunch of languages which created for this purpose (compile to JS): purescript, elm, typescript, etc.
Modern browsers can use webassembly binary packages. It differs from JS, but also don't have access to DOM.
The real question you have raised here is:
Whether we can use languages like C# or python for DOM manipulation like JS?
In simple words, the answer is no. But if you are using any kind of parser, you will get a feeling that you are doing something in python like HTML but again on browser it will be HTML only.
Rather I will say... there is very big difference between mark up language (front end language) and server side language.
HTML is used as a markup to show some content on web page. You can use some templating though but that will again finally be compiled into HTML only.
Now comes the role of JS, whatever elements have been created on web page, Javascript has power to perform operation/manipulation on them. This is called DOM manipulation which is only possible through some front end language. And currently we have only Javascript as per my knowledge (Please somebody correct me if I am wrong)
Now comes the role of C#, python or PHP. These languages are for back end jobs. Anything you are sending from front end, will be processed at backend and these languages are used for those purpose so, DOM manipulation thru C# is a big NO. You need javascript (jQuery or other library) for that.
Thanks,
Hope it helps.
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 7 years ago.
Improve this question
I'm trying to accomplish the following:
Pull information from a module through Python. [Accomplished]
Constantly pull information from Python for use in HTML.
Avoid writing the entire HTML/CSS/JS document in print statements.
I've seen the term CGI thrown around, but don't really understand how it works. Simply put, I want to run the Python script which returns an integer value. I then would like to take that integer value into JavaScript so that it may update the designated tag. It should be able to execute the Python script every two seconds, receive the output, then apply it to the page. I do not want to write out the entire HTML document in Python by doing one line at a time, as I've seen some people doing on sites I've found.
It seems like doing something like this is far more complicated than it should be. The page should run, call the script for its output, then give me the output to use.
Well if you don't know what CGI is and find that what you ask for is "far more complicated than it should be", you first have to learn the HTTP protocol, obviously, and that's way to broad for a SO answer.
Basically what you want requires:
an html document
some javascript code, either linked from the document or embedded into it
a web server to serve the document (and the javascript)
a web server (can of course be the same as the previous one) that knows how to invoke your python script and return the result as an HTTP response (you'll probably want a json content type) - this can be done with plain CGI or with a wsgi or fcgi connector, in your case CGI might well be enough.
Then in the browser your javascript code will have to issue a GET request (ajax) every x seconds to the web server hosting the Python script and update the DOM accordingly.
This is all ordinary web programming, and as I said, a basic understanding of the HTTP protocol is the starting point.
Trying to write anything from scratch, if you don't know anything about the subject, is always going to be complicated.
That is why there is a whole world of tools to help you. I don't think you want CGI at all; look into one of the Python micro frameworks, in particular Flask. The tutorial there should give you the introduction you need.
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
Most traditional MVC frameworks include their own templating solution (Jinja2, Mako, etc). If one decides to use one of those new ui frameworks such as angular or backbone, they seem to encourage the use of front end templating solutions.
Is there any difference in performance? What are the pros and cons of going either way? Are there issues in ie or other browsers when using some of theses js templating solutions?
My take on this is simple, really.
Use a server side templating engine when you want to template the structure of a site. Use a client side templating engine when you want to template the data of the site. And there is nothing wrong at all with using both, as long as they don't have a large amount of competing tokens.
A VERY common example of this is using ASP.Net MVC to manage the bulk of a site structure using the razor template engine, and using a JavaScript client library such as Angular.js to simplify the data structures on the individual pages.
Depending on the situation, one major factor can be a significant change in bandwidth usage.
For example, my newest project includes the ability to have colour codes in chat (and other places). These codes look like:
`1blue `2green `3yellow `4red `bbold on `Bbold off `b`iBold Italic...
I could parse this server-side and return:
<span style="color:blue">blue </span><span style="color:green">green</span>...
But see how I only did two words and I'm already going longer than the source text! Instead, I chose to implement the parser in JavaScript, on the front-end. This takes a lot of processing off of the server (which would otherwise have to parse this stuff for every single user) to the client (where only one user is being dealt with).
It also had the advantage that I could implement a live preview just by plugging in to the same parser, but that's irrelevant here.
Additionally, client-side templates can be cached, further reducing the amount of data that needs to be sent. This can be particularly beneficial to mobile users, who may not have unlimited data (those poor people... I weep for them... not really)
Personally, given the choice, I'd strongly recommend client-side templating (although in my usual style, I would shun all pre-made solutions and make my own XD I'm weird like that) for a variety of performance reasons. Obviously, the major downside is "no JavaScript = no website", but I'm fine with that since the entire site relies on JS...
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 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
Good day! I want to apologize for the bad title, but I am not really sure how to express my question in a short manner.
Consider the following situation: You have an html form (regardless with what fields) and you have some empty spaces. For example consider it has a space for text and a space for receiver. They are both already styled with css, but the inner html is left empty.
My question is the following: Is it possible to create a program with JavaScript which will edit (rather set) the inner html of the file to something and create a new file containing it.
My research so far hasn't been too successful, and I am starting to think that it is not possible (because you can't directly read files from JavaScript) So I decided to ask here as a last resort.
As far as I know, for security reasons, Javascript cannot access your file system and this is by design. Hence, you cannot read or change files using Javascript or any client based programming language. You need server side languages like PHP, C# to achieve your goal.