JS dociment.write can be a from of eval

Discussion about any web related scripting languages like JavaScript, ASP, and PHP.
Post Reply
Immanuel
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 1
Joined: Sun Nov 01, 2015 2:39 am

JS dociment.write can be a from of eval

Post by Immanuel » Sun Nov 01, 2015 1:28 pm

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
Site Admin
Posts: 3384
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

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

Post by Albert Wiersch » Mon Nov 02, 2015 11:12 am

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
Image
Albert Wiersch

Post Reply