How To Create Website With No HTML In Source Code - javascript

I've wondered this before, but never gotten an answer. Then just today I came across another site: http://ruralcoz.com/ with no html in the source code. Only a minified script. Does anyone know how the developer built this site, and why they chose to replace all the html with javascript? What's the benefit of this? How is this done?
Thanks!

That's a React app. React uses JavaScript to create everything on the page and then loads it into the one root div on the page.
There are advantages to doing it this way and you can read more about it here

That site does have HTML in the source code, specifically:
<!doctype html>
<html lang="en">
<head>
<title>Four Points Funding</title>
<link href="/static/css/main.d6132581.css" rel="stylesheet">
...
</head>
<body><noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="text/javascript" src="/static/js/main.0673017f.js"></script>
</body>
</html>
All of the above is HTML markup, and pages must have HTML to be rendered as HTML pages. There's no way around that.
What this site is lacking is content in the <body>, which might seem a bit odd, but is very doable. Javascript can be used to create elements and to insert them into the HTML, which is happening here. For example:
<script>
const div = document.createElement('div');
div.textContent = 'Body content!';
document.body.appendChild(div);
</script>

Related

External javascript not working?

I just started learning javascript about 30 minutes ago. I'm doing an online course and they gave me this code as an example. The person in the video did the exact same thing, but it only works for me when I do inline not external. My .js name is right and they're in the same folder.
The html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Basics</title>
<script src=“cripts.js”></script>
</head>
<body>
<div class="container">
<h1>Where to place your JavaScript code.</h1>
</div>
</body>
</html>
and the js:
alert("YOU");
Nothing appears for me. I've tried everything to make it work, including different browsers. Could it be my computer or did I make a simple mistake?
It looks like your quotes are invalid :') Good beginner move! But it will be a simple fix. Note the “ should be ", this usually happens when copying and pasting code!
<script src="cripts.js"></script>
Also make sure your path and file name is correct?! cripts.js sounds like it is suppose to be scripts.js
A beginner mistake I made was to use <script>...</script> tags in the external javascript file. From HTML if you use:
<script type="text/javascript" src="../myApp/myFile.js"></script>
Then the external js file should just contain just the code such as:
function myFunction {}
with no script tags. This is unlike linking to external css files which include the <style>...</style> tags.

Hierarchy structure for browser game development

I'm looking into creating browser game development. I have a strong background in C programming (c/c++/c#) and web development (html/css/wordpress/some JS). This area of programming seems like chaos and no one has a firm framework that works well and is good.
I've been exploring at libraries available such as gameQueryJs and other tutorials I've found such as Canvas Tutorial, I keep running into the same issue.
They all just jump STRAIGHT into the code. No pre-set up, how the HTML page should look like, just nothing. They all go BANG, right into the javascript.
Before I get into the javascript I need to set up the web page. I am wondering how such a page would be designed like and how to import scripts correctly.
For example, if I wanted to add jquery and the gamequery libary, would I add it like this?
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="js/jquery-3.1.0.min.js"></script>
<script src="js/jquery.gamequery-0.7.1.js"></script>
<title> GAME TITLE </title>
</head>
<body>
<div id="game-txt">
<h1> GAME TITLE </h1>
</div>
<div id="wrap">
<div id="canvascontainter">
<canvas id="canvas" width="300" height="300"></canvas> -- ignore this, this was when I was playing with the canvas tutorial
</div>
</body>
</html>
<!-- SCRIPT STUFF DOWN HERE? -->
To further explain my issue, here is gameQueryJS's first line of code they introduce to you to use.
var PLAYGROUND_HEIGHT = 250;
var PLAYGROUND_WIDTH = 700;
$("#playground").playground({height: PLAYGROUND_HEIGHT, width: PLAYGROUND_WIDTH});
Where does that go? What is the playground id they are manipulating on the page? They just throw that line at you like every other tutorial I've found without explaining anything.
Javascript can be placed in script tags or in a seperate file just like the gameQueryJs libraries that you are loading.
Where you put the script tags is almost entirely up to you, although most people will put them in the section.
Putting them below the closing tag of the page is not correct however. Unfortunately most browsers will accept and execute it even then because they try quite hard to make every page they get served work. For more on where to place script tags check W3Schools
The playground they refer to is an element that you'd have on your page, in their example from lesson one it is a div with the id playground.
Also, if you check the first example that they give you can select Edit with JSFiddle the code they show there should help anwser part of your question as well as add to the lack of information you complained about.

Load markdown file into HTML's textarea

I'm trying to use Remark.js to create HTML presentations based on the template provided. The template includes the textarea tag with id='source' where the markdown is simply copied in. I wanted to go for a solution where I can leave the template and just change the file that is loaded, so that I don't have to work inside the HTML file and keep the markdown separate.
I've tried using jQuery (I'm a noob) but it does not seem to work, the page stays empty. Here's what I tried:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>My presentation</title>
<link rel='stylesheet' type='text/css' href='presentation.css'>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js'></script>
<script src='https://gnab.github.io/remark/downloads/remark-latest.min.js'></script>
</head>
<body>
<textarea id="source"> </textarea>
<script>
$('#source').load('presentation.md');
</script>
<script>
var slideshow = remark.create();
</script>
</body>
</html>
I don't get any errors in the JS console, but I also don't see anything. When I simply copy the file into the textarea it works, as expected, so the markdown file is OK.
I ran Chrome with the --allow-file-access-from-files so that at least I don't get the cross-origin requests error. However, that is not satisfactory as I intend to place the HTML file (and the related files) in Dropbox. If possible, I don't want to run a web server locally as it's just a 'simple' HTML file with some text copied in from another file.
What's the best way to achieve this, i.e. copying in a file as-is?
This willl solve your problem:
Create the remark after you loaded the data by adding the call to your callback function.
<script>
$('#source').load('presentation.md', function() {
var slideshow = remark.create();
});
</script>

Load an HTML when another is display without modify him

Before all, I just want to apologize to my bad English (french school are not so good for practicing other languages ...).
I have a header.html on my site. I cannot modify him because it's not mine.
I just want to call an other html (one of mine, that i can modify, we can name it toto.html), when header.html is display (in other words, it's not a Java functions who call my other html, it's header.html).
I've tried some Jquery functions (like load()), Javascript and even the macro <#include from HTML, but without success.
Thanks to all for your responses.
Have a good day !
I have the following files in one directory:
helloworld.html
<p>hello!</p>
test.html
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$("document").ready(function() {
$('#container').load('helloworld.html');
});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
Loading test.html in browser produces "hello!", so check if you jQuery is loaded properly.
Can you post example here to show us the context and how your page header.html is included in your site ?
I thinks it's not possible to do that : "(in other words, it's not a Java functions who call my other html, it's header.html)"
If you're not able to modify header.html or the way your page is called, it would be difficult to load anything else.

My embedded Javascript is not displaying on an html canvas and I would like to know the structure for this in the future

I apologize as I am a relative beginner to programming, especially for the web. I am currently try to utilize the videos from code player but the website does not show how each file is linked together through the html. The below is the current structure of the html file. I would like to know how this needs to be changed to get the javascript to display in the canvas. (The style sheet works correctly)
<!DOCTYPE html>
<html>
<body>
<link rel="stylesheet" type="text/css" href="GaugeStyling.css">
<canvas id="canvas" width="300" height="300">
<script type="text/javascript" src="gaugescripts.js"></script>
</body>
</html>
i am too a relative beginner but for a start you don't need the type in the script anymore and you put the script in the head section, which you don't seem to have.
In your gaugescripts.js, i presume you have a line such as:
var canvas=document.getElementById("canvas");
if you so that how you connect the two after the i'd need to see the script to see where your problem lies.
good luck

Categories

Resources