JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 2nd, 2013, 08:30 AM
littlebigman littlebigman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2010
Posts: 28 littlebigman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 41 m 2 sec
Reputation Power: 0
Question [jshint] "document.write can be a form of eval."

Hello

I'm learning JavaScript by reading "The Definitive Guide".

I saw JSHint and JSLint recommended to catch syntax errors, but I don't understand why they don't like this code:

Code:
var s = "hello world!"; // A string
var word = s.substring(s.indexOf(" ") + 1, s.length); // Use string properties
document.write(word);


Here's the report:
Quote:
Line 3: document.write(word);
document.write can be a form of eval.


Why is document.write() wrong, and what else should I use to simply output something to the browser?

Thank you.

Reply With Quote
  #2  
Old January 2nd, 2013, 10:16 AM
AndrewSW's Avatar
AndrewSW AndrewSW is offline
JavaScript is not spelt java
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2011
Location: Landan, England
Posts: 743 AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 22 h 56 m
Reputation Power: 164
document.write() should no longer be used as it is possible for a script or command to be embedded in it, which will be interpreted by the browser.

Instead, wait for the page to finish loading, and use code such as the following:

document.getElementById('someid').innerHTML = "Some text";
__________________
"The mysql extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used." the docs

Reply With Quote
  #3  
Old January 2nd, 2013, 10:22 AM
littlebigman littlebigman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2010
Posts: 28 littlebigman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 41 m 2 sec
Reputation Power: 0
Thanks for the tip.

Reply With Quote
  #4  
Old January 3rd, 2013, 08:48 AM
AndrewSW's Avatar
AndrewSW AndrewSW is offline
JavaScript is not spelt java
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2011
Location: Landan, England
Posts: 743 AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 22 h 56 m
Reputation Power: 164
There is also JavaScript Lint which is somewhat simpler than JSLint in particular. JSLint is overly prescriptive.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > [jshint] "document.write can be a form of eval."

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap