Jump to content

can someone please tell me what is going on in this code? its bizarre


p4c

Recommended Posts

can someone please tell me why this is working? I figured it out by accident, and have no idea what the heck is going on here? This works in chrome, IE, and firefox; can someone tell me why? If you remove from the body the

element from the second CC or the first CC then the whole thing doesn't work in IE, what is so special about that "." and that "ghost" CC that does nothing? I am very confused on this, any help would be appreciated.

 

im using win vista/xampp/ie7, chrome, firefox; (for those who migt try replicating this oddity?)

 

my file is as follows:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

 

 

===================================================================================

this is the contents of hed.php that is being called here:

<?php

$msgr = " document.write('

some title

 

 

.

 

 

var newcontent = document.createElement('div');

var scr = document.getElementById('syndication_no');

 

newcontent.id = 'outside_content_container';

newcontent.appendChild(document.createTextNode('Here is some syndicated content.'));

scr.parentNode.insertBefore(newcontent, scr);

 

// simply a confirmation that the div was constructed

 

if(newcontent.id = 'outside_content_container')

alert('The Div with the Id: ' + newcontent.id + ', has been built!');

 

 

Link to comment
Share on other sites

i realize that the comments are not correct. I have a few questions, first, why is IE parsing the !IE content. but not the IE content. saecond why wont it work if i remove the

.

that i put in there or the first IE CC? the whole thing is bizarre, im just trying to figure how & why it works? It probably wont validate, and i usually am very standards compliant, im just trying to figure this out.
Link to comment
Share on other sites

The second conditional comment doesn't look at all right to me.

 

[if !IE] means NOT IE and the comments should be different, like this:-

....

 

compared with a conditional comment for IE

 

Note the missing -- twice in the NOT IE cc.

 

See http://www.javascriptkit.com/howto/cc2.shtml

 

A couple of points:

 

1. !IE will not work. Only IE can read conditional comments, so having !IE ... doesn't make sense - if you follow what I mean.

 

2. don't use document.write(), that's really old school 1996 stuff. Use DOM scripting instead. Check out my videos on this:

 

http://www.killerjavascript.com/videos/

 

So why is it not working? Probably because when IE comes across the !IE declaration ... IE is says to itself:

 

"... what the snap is this? " And then, IE probably does something weird that is screwing up the rest of your code.

 

 

To be clear, you can have !IE6, !IE7 or IE8 ... but you can't have !IE.

 

Stefan

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...