I am trying to create a dialog box that will appear only if the browser selected is IE (any version) however I get this error:
Message: HTML Parsing E
Like Sergey Kirienko said: use conditional comments. The code below will only be executed by internet explorer. Microsoft has good information on this page.
<!--[if IE]>
<script type="text/javascript">
showDialog('¡Aviso Importante!','message','warning',10);
</script>
<![endif]-->
If you want a specific version you can test for that too:
<!--[if lte IE 7]>
<script type="text/javascript">
showDialog('¡Aviso Importante!','Your are using a too old version of Internet explorer. Please upgrade','warning',10);
</script>
<![endif]-->
javascript works very easy with navigator.appName. (see http://de.selfhtml.org/javascript/objekte/navigator.htm) You can create an if-query with this. Very easy, just try it!
Reading the doc linked by porneL, I found a simple workaround for this problem: Adding a parameter 'defer' to the script, all works fine.
<script defer=true>
I had this same problem. My issue was that I was calling a Javascript function before the containing div
was closed.
To fix the problem, I call the Javascript function within the jQuery ready
event handler:
$(document).ready(function(){
some_random_javascript_function();
});
You're modifying document while it's being loaded (when browser hasn't "seen" closing tag for this element) . This causes very tricky situation in the parser and in IE it's not allowed.
IE blog has explanation of this.
The solution is to modify another element that's earlier in the document and has been loaded completely (where browser already saw closing tag for it).
BTW: The string </
is not allowed in <script>
element. Use <\/
which is a safe equivalent in JS strings.
Maybe a little late, but this error also pops up if you are using SWFObject and have 2 divs with the same id.
I had duplicate divs, [with id="flashcontent", thanks to copy&paste].
Solved by renaming the divs with unique ids.