JS document.write can be a from of eval

For general web development questions that are not specifically related to CSS HTML Validator. This includes (but is not limited to) general HTML, CSS, Accessibility, JavaScript, and SEO questions.
Post Reply
Immanuel
Rank 0 - Newcomer
Posts: 1
Joined: Sun Nov 01, 2015 2:39 am

JS document.write can be a from of eval

Post by Immanuel »

In my HTML document I have JS Code for calling a JS document:

"createHeader("Diskurs18E.htm", "Notrnslt.htm", "Diskurs18.htm");"

In the JS document I post code for HTML with "function create.. document.write"
"function createHeader (Header1URL, Header2URL, Header3URL) {"use strict";
document.write(' <table class="Verdana..."

But here I got the CSE validator errors
[JSHint] Problem: implied global: document
[JSHint] Problem: unused variable: createHeader
[JSHint] Problem: document.write can be a form of eval.

What can I do to correct these errors in CSE-Validator?
Thanks and regards
Friedrich
User avatar
Albert Wiersch
Site Admin
Posts: 3783
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: JS document.write can be a from of eval

Post by Albert Wiersch »

Hello,

Here is the page on JSHint options:
http://jshint.com/docs/options/

For the implied global message, you can tell JSHint you will be using browser globals by using this option: "--browser=true". Add that to the 'Options' string in the JSHint page of the Validator Engine Options. Alternatively you could add this comment to the top of your JavaScript document:

Code: Select all

/* jshint browser:true */
For the unused variable message, you can tell JSHint about global variables that are defined in the current file but used elsewhere by adding this to the top of the JavaScript document:

Code: Select all

/* exported createHeader */
To specify more than one variable, separate with commas like this:

Code: Select all

/* exported export1,export2,export3 */
For 'document.write can be a form of eval.', here's a good link:
http://www.jameswiseman.com/blog/2011/0 ... m-of-eval/

You can right-click and disable that message if you want. In future updates I've made it a warning and added a message ID so the message can be changed or disabled that way if you don't want to see it anymore.

As for document.write, it should be avoided if possible. See the info about it here:
http://stackoverflow.com/questions/1504 ... rm-of-eval
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
Post Reply