Reputation: 152647
This code giving error in IE
var tip = "<p>Most computers will open PDF documents ";
tip += "automatically, but you may";
tip += "need to download <a title='Link to Adobe website-opens in a new window'";
tip +=" href='http://www.adobe.com/products/acrobat/readstep2.html'
target='_blank'>Adobe Reader</a>.</p>";
$(document).ready(function(){
//IF NUMBER OF PDF LINKS IS MORE THAN ZERO INSIDE DIV WITH ID maincontent
//THEN THIS WILL PUT TIP PARAGRAPH AS LAST CHILD OF DIV
if($("div#maincontent a[href*='/pdf']").length>0){
$("div#maincontent").children(":last-child").after(tip);
}
});
See this page in IE : http://jsbin.com/oliho4
Upvotes: 4
Views: 4108
Reputation: 506
Script on this page may be useful: http://blogs.msdn.com/ie/archive/2009/09/03/preventing-operation-aborted-scenarios.aspx
Upvotes: 0
Reputation: 54605
To me it seems obvious that you try to modify some element before the page has finished loading. At least that's exactly what you do on your demo page. You don't wrap the code in $(document).ready()
as you did in the question
Try this demo-site instead http://jsbin.com/ivuqa which correctly wraps the relevant lines in ready()
Additionally there might be some problems when using XHTML. In that case just wrap the offending javascript part like this. (CDATA to satisfy the XML validation, javascript multiline comment to hide the the cdata from browser which don't understand it and thus would fail to run the javascript.
/* <![CDATA[ */
var tip = "<p>Most computers will open PDF documents automatically, but you may need to download <a title='Link to Adobe website-opens in a new window'";
tip +=" href='http://www.adobe.com/products/acrobat/readstep2.html' target='_blank'>Adobe Reader</a>.</p>";
/* ]]> */
Upvotes: 4
Reputation: 8980
Is it the infamous alert that returns a blank page in IE?
It's a known and documented IE issue.
This error usually occurs when you're trying to modify a DOM element before the page finished loading.
Try moving your script at the bottom of the page.
Since you're using document ready, I don't think this causes the problem. Maybe is it because of another script on your page?
EDIT:
You can also try to fire your function on the body's onload
attribute. I just read this here.
EDIT 2: I didn't see your link. Jitter is right, you're not using jQuery's $(document).ready()
Upvotes: 0