homepage Welcome to WebmasterWorld Guest from 54.234.141.47
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
IE not showing this correctly
Internet Explorer does not render this script correctly
metaman01

5+ Year Member



 
Msg#: 3602246 posted 6:43 pm on Mar 16, 2008 (gmt 0)

I have this issue with Internet Explorer not rendering the page as I suppose it should using some external JS files.

<script type="text/javascript" src="myscript1.js"></script> outputs some text 1
<script type="text/javascript" src="myscript2.js"></script> outputs some text 2

Then I try this:

function showlist(){
var text1 = '<script type="text/javascript" src="myscript1.js"></script>';
var text2 = '<script type="text/javascript" src="myscript2.js"></script>';
document.write('<ul><li>'+ text1+'</li><li>'+ text1+'</li></ul>');
}

Opening this in Firefox it outputs:

* some text 1
* some text 2

(And this is what I want to.)

Opening this in IE gives this:

*
*
some text 1 some text 2

First the bullet points are rendered, then the text. Does anybody know why this is happening, and what to do to avoid it?

 

MarkFilipak

5+ Year Member



 
Msg#: 3602246 posted 11:52 pm on Mar 16, 2008 (gmt 0)

Try escaping the forward-slash characters in the string definitions like this:
var text1 = '<script type="text\/javascript" src="myscript1.js"><\/script>';
var text2 = '<script type="text\/javascript" src="myscript2.js"><\/script>';
document.write('<ul><li>'+ text1+'<\/li><li>'+ text1+'<\/li><\/ul>');

Let me know if it fixes your problem.

DrDoc

WebmasterWorld Senior Member drdoc us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3602246 posted 12:52 am on Mar 17, 2008 (gmt 0)

The problem is that IE first writes the HTML, then evaluates the scripts.
Not sure if there's a way around that ...

metaman01

5+ Year Member



 
Msg#: 3602246 posted 7:17 am on Mar 17, 2008 (gmt 0)

Thanks, both of you, I will try to escape the character to see if it is any difference.

Since I use JavaScript to print the HTML I thought that it would be the same, but maybe this has something to do with the external scripts?

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3602246 posted 3:12 pm on Mar 17, 2008 (gmt 0)

Dr Doc, would this do it?

If those scripts output text, they certainly (or should, or could) contain functions that output the text. If the scripts are inline, wrap them in a function. Then you should be able to do

window.onload = function () {
var text1 = output_from_script_1_function();
var text2 = output from script_2_function();
}

then wherever you need it,

<script type="text/javascript">
document.write('<ul><li>'+ text1+'</li><li>'+ text2+'</li></ul>');
</script>

Alternatively, just add your formatting and document.write() to the scripts and drop it in.

<ul>
<script type="text/javascript" src="myscript1.js"></script>
<script type="text/javascript" src="myscript2.js"></script>
</ul>

DrDoc

WebmasterWorld Senior Member drdoc us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3602246 posted 6:09 pm on Mar 17, 2008 (gmt 0)

<script type="text/javascript" src="myscript1.js"></script>
<script type="text/javascript" src="myscript2.js"></script>
<script type="text/javascript">
var text1 = output_from_script_1_function();
var text2 = output from script_2_function();
document.write('<ul><li>'+ text1+'</li><li>'+ text2+'</li></ul>');
</script>

That would work ...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved