-2

Possible Duplicate:
Why split the <script> tag when writing it with document.write()?

I have this code on my page :

var print_popup = window.open("", "Booking", "width=950,height=680, scrollbars=1");

print_popup.document.write("<html xmlns='http://www.w3.org/1999/xhtml'>");

print_popup.document.write("<head>");
print_popup.document.write("<script src=\"http://code.jquery.com/jquery-1.7.1.min.js\" type=\"text/javascript\"></script>");
print_popup.document.write("</head>");

print_popup.document.write("<body>");
print_popup.document.write("<div class='element'>Hello</div>");
print_popup.document.write("<div class='element2'>Marco</div>");
print_popup.document.write("<script type='text/javascript'>$('.element').hide();</script>");
print_popup.document.write("</body>");
print_popup.document.write("</html>");

print_popup.document.close();

So, when I open the popup, I insert the jquery Library. Than, I'd like to hide element. On Firefox/Chrome there are no problems; on IE (8) the browser open a about-blank popup, and the window get frozen (I need to force-close the browser).

I know I should hide the element with CSS, but for other operations I need jQuery.

Why this? And how can I fix it?

EDIT

Tried replacing < with \x3 but still the problem. It seems to crash appending just the jQuery Library...

Community
  • 1
  • 1
markzzz
  • 47,390
  • 120
  • 299
  • 507

1 Answers1

0

try to wrap $('.element').hide(); into $(function(){$('.element').hide();});

Distdev
  • 2,312
  • 16
  • 23