Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

alert is not working

 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys,

I am having a sample code. Which is not running properly. It displays instead of alert. My code is below.

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The browser does not understand that the script tag in the alert is not the closing tag.

Instead of looking at the html code, lets look at some JavaScript.

Your problem is equivalent to



See the issue there? We want the whole string, but it chops it off early at the ' after Eric and throws an error. In the case of the HTML it stops it at the script tag in the code and than renders whatever else as text on the page.

So how would be fix the JavaScript example? We would escape the '




And it would work fine.

What we need to do for the HTML issue is to break up the script tag into two parts.




The browser will no longer see the closing script tag when it is rendering the page.

Eric
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:The browser does not understand that the script tag in the alert is not the closing tag.

Instead of looking at the html code, lets look at some JavaScript.

Your problem is equivalent to



See the issue there? We want the whole string, but it chops it off early at the ' after Eric and throws an error. In the case of the HTML it stops it at the script tag in the code and than renders whatever else as text on the page.

So how would be fix the JavaScript example? We would escape the '




And it would work fine.

What we need to do for the HTML issue is to break up the script tag into two parts.




The browser will no longer see the closing script tag when it is rendering the page.

Eric




You may be right. But if i remove xhtml doctype and use



It works. Now i am unable to understand what is happening here.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are saying you changed it to look like:



I would still expect issues there.
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:So you are saying you changed it to look like:



I would still expect issues there.



Remove doctype. It will work.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what horrible browser is this?

In the end you need the doc type on the page.

Eric
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:And what horrible browser is this?

In the end you need the doc type on the page.

Eric


As far as i know. if you use html not xhtml. You dont need doctype. Please correct if i am wrong. Please help. If you remove doctype the code above displays alert box.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic