HTML Comment after </html> - html

Is this safe for most modern browsers or will it turn into a huge abomination?
eg:
<html>
<head>
<title>Please work</title>
</head>
<body>
My Awesome Body
</body>
</html>
<!-- Generated in 1.337 seconds -->

My guess is that, as long as you keep the DOCTYPE declaration at the very top of the page, you shouldn't have any issue with placing comments anywhere you want.
Although, it is best to always try for different browsers.

Try to check it with a HTML validator

Either check it with a validator or run your code personally through all the available web browsers, always the best way to go about that!
However, you should be fine as long as you avoid putting code above the "<!DOCTYPE>" line

it will work but Im not sure it is valid html.
You can run an html code without the <html> tag at all, the browsers will still accept it.
But its not good practice. try keep your html code valid

Related

Why does innerHTML behaves differently when it has <html> as a content?

Can anyone tell me why special here?
<html>
<head>
<script src="editor.js"></script>
</head>
<body>
<div id="scripts" class="scripts">
Editor.Execute('<html>Html String</html>');
Editor.Execute('<something>Html String</something>');
</div>
</body>
</html>
document.getElementById("scripts").innerHTML shows something however html dissapears.
Execute('Html String');
Execute('<something>Html String</something>');
It behaves the same way in Firefox and Chrome.
You're running into this issue.
Basically, the browser sanitizes out the HTML tags before your JavaScript can even access the page – you can check in the Chrome elements inspector, your <html> tag is not there.
I guess the answer depends on what exactly you're trying to do, but if you're just trying to output that code onto a web page, you can just escape the characters:
<html>
<body>
<div id="scripts" class="scripts">
Execute('<html>Html String</html>');
Execute('<something>Html String</something>');
</div>
</body>
</html>
Then document.getElementById('scripts').innerHTML will output:
Execute('<html>Html String</html>');
Execute('<something>Html String</something>');
And then you can replace the HTML entities in JavaScript.
Without knowing what you do in that Execute() it is hard to say what is going on there.
Just in case: HTML document can have one and only one <html> node.

Why doesn't this show up on my screen?

For some reason this little bit of HTML won't show up when I open the file in Chrome, or any other browser for that matter. The code is shown below:
<!DOCTYPE html>
<html>
<head>
<title>
#
<title>
<style>
</style>
</head>
<body>
<table>
<tr>
<tb>Home</tb>
<tb>About</tb>
<tb>Freelance</tb>
<tb>Contact</tb>
<tr>
</table>
</body>
</html>
With that, does anyone know how to make a better menu bar?
All of the other comments and answers are correct - there are multiple errors in the HTML you've posted.
However, any of those errors will still show SOMETHING on the page.
The error that is causing nothing to show up is simply that you haven't closed your <title> tag. You've got 2 opening tags rather than <title>#</title>
Corrected:
<html>
<head>
<title>#</title>
<style>
</style>
</head>
<body>
<table>
<tr>
<td>Home</td>
<td>About</td>
<td>Freelance</td>
<td>Contact</td>
<tr>
</table>
</body>
</html>
As #sideroxylon noticed, you did a major issue when you forgot to close <title> tag. After fixing it you should see all your content.
Additional points:
Your missing <html> surrounding tag.
You wrote <tb> instead of <td>.
You should also use indentation for more readable code.
From the comments, I can see three problems with your HTML:
You never closed your <title> tag (all credit to sideroxylon for that) so none of the other HTML will render outside of it.
You wrote <tb> instead of <td>, and <tb> isn't a valid HTML tag. It might function, but using invalid HTML tags is a very bad habit to get into.
You're missing <html> tags. You say that you have them in your actual code, so that's good, but when you post code, please post all of it.
As to a better way to make a header bar, it's probably a better idea to use an unordered list and CSS than a table. There are plenty of tutorials on how to do that -- a simple Google search brings up quite a few. Feel free to choose which is best for you. CSS tends to be easier to manage and customize, as well as producing better-looking results on the end-user's screen, once you get the hang of it.

Why does Chrome Developer Tool add elements not in the file?

When I have a simple HTML markup like this:
<!DOCTYPE html>
<html>
<head>
<title>lawl</title>
</head>
<body>
</body>
</html>
When viewing the elements of the document, in the Chrome Deceloper Tool(F12) it looks likes this:
<!DOCTYPE html>
<html>
<head>
<title>lawl</title>
<style type="text/css"></style> <-- what the?
</head>
<body>
</body>
</html>
So, my question goes: Where does the style tag come from? What added it, and why?
Hope you guys can clear this up for us, it's been quite the subject the last 10 minutes in class ;-). Also worth mentioning; a class got added to a empty div in another document when the teacher tried it.
Edited title.
Chrome plugins can get access to your DOM, and so does the development tools. In this particular case, I think the development tools is the one to blame.
The empty style tag is probably a placeholder for injected CSS.
If you open the source code (view-source:www.example.com), you will see that your DOM is perfectly fine.
99:1 that the <style> element is a stylesheet injected by your AdBlock (or similar) extension.

How to fix the font issue in HTML?

I have Html (hello.html) like bellow
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test</title>
</head>
<body>
<div>
¿Hola cómo está?
</div>
</body>
</html>
It shows out as "¿Hola cómo está?" when run in browser
Is there any solution to get correct out put without altering the
hello.html file?
I hope that, it is in Spanish language but i looking for any other solution like as change the encode type or font in browser or editor.
Edit: Just noticed the requirement. But some Spanish characters require Unicode and you have to declare that in your html file.
Put this in your head.
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
I don't see whats wrong, if you are refering to the font type in the html and the webpage is different is because of your editor, if you really want to change the font you will need to set the font tag around your text or even better define it in the CSS
Based on the clarification in the comment section to your question....
If you are using Google Chrome, and your computer is set to an English locale, load the page, then right click on the body, and select "Translate to English."
Sounds like an interview trick question, rather than a programming one.
No.
You cannot do this without altering the html file.
Place this <meta> tag in your Head Section
<meta charset="UTF-8">

weird issue with html: markup is correct but dev tools show <title> moving to <body>

I've got this weird issue going on. I'm using Codeigniter 3.0-dev and Smarty 3.1.4 in the backend, but I don't think it's relevant.
I have this really simple html:
<!DOCTYPE HTML>
<html>
<head>
<title>some page</title>
</head>
<body>
asd
</body>
</html>
now. when I view the source of this page, on any browser (tried Opera 10.52, Firefox 7.0.1, Chrome 14 and 15, IE9) the markup is exactly like above. now, when I use firebug or chrome's dev tools it moves the title tag in the <body>, and if I have meta or anything else in the <head>, it moves those items in the <body> aswell. firefox's firebug shows me this:
<html>
<head></head>
<body>
<title>test</title>
asd
</body>
</html>
why does this happen? any ideas, at all?
Elements that appear to be in head in the mark-up, can end up inside body in the DOM, if the parser sees something before the moved elements that is only permissible in the body of HTML. For example, a double BOM (byte-order-mark) at the start of the file may not show up in View Source, but will cause the parser to think that it has entered the html body section, and all the head elements in the mark-up will end up in the body in the DOM.
What Alohci said, plus both Firebug and the Chrome debugger often move things around to suit themselves. The source then looks wrong when viewed in those debuggers.