• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

alert is not working

 
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic