“defer” for IE7′s operation aborted error

IE has this "operation aborted" problem (MSDN article) when you try to change your parent while it's not ready.

This is the example they give that causes this error:

<html>
  <body>
    <div>
      <script>
        document.body.innerHTML+="sample text";
      </script>
    </div>
  </body>
</html>

Turns out you can easily solve it by just adding a defer attribute to the script. This works just fine:

<html>
  <body>
    <div>
      <script defer>
        document.body.innerHTML+="sample text";
      </script>
    </div>
  </body>
</html>

Demo page here

BTW, this operation aborted may bite you if you decide to append a script node to the body, like

var js = document.createElement('script');
js.async = true;
js.src = "http://tools.w3clubs.com/pagr/1.sleep-2.js";
document.body.appendChild(js); 

So it's not a good idea to append to the body like this when you don't control the page you're adding this code to, although document.body seems to be always available even when the page doesn't have a <body> tag

21 Responses to ““defer” for IE7′s operation aborted error”

  1. stoyan Says:

    Via Paul Irish: An issue with IE9 and defer
    https://github.com/paulirish/lazyweb-requests/issues/42#issuecomment-1901803

  2. Mathias Bynens Says:

    Note that this is non-standard behavior — @async and @defer should be ignored for inline scripts as per the HTML5 spec. In other words, this hack is invalid HTML, but it won’t change the expected behavior in non-IE browsers. \o/

  3. JSPatterns.com » Blog Archive » The ridiculous case of adding a script element Says:

    [...] Exploring common JavaScript patterns and anti-patterns   « “defer” for IE7′s operation aborted error [...]

  4. John-David Dalton Says:

    Support for the “defer” attribute is inconsistent and buggy across browsers (more than just IE9 issues…). Using it for anything where you want consistency/stability is probably not a good idea. Common issues are scripts execute out of order or may execute after the DOMContentLoaded event has fired.

  5. Diego Perini Says:

    The fact that browsers automatically insert a body tag even when no body tag is present in the HTML source doesn’t mean one can append elements to the body as soon as Javascript executes.

    That can happen only after DOMContentLoaded has notified that the HTML source has been completely parsed and the corresponding DOM nodes have been put in place.

    On IE browser (< 9) catching this moment is useful to ensures that DOM manipulations can happen as soon as possible and at the same time avoids the "Operation aborted" error you talk about !

    The "defer" attribute is a source of problems on IE itself ! Avoid it when you can !

    Diego

  6. The ridiculous case of adding a script element | JSSpy | The ultimate resource for JSSpy info. Edit this at (Settings > Tagline) Says:

    [...] operation aborted may be solved with a defer, but maybe not in [...]

  7. “defer” for ie7′s operation aborted error | JSSpy | The ultimate resource for Javascript info. Says:

    [...] http://www.jspatterns.com/defer-for-ie7s-operation-aborted-error/ Share on  Twitter  Facebook  Google Reader  Ping.fm No Comments Related [...]

  8. ashleyallyson.com Says:

    Hi there, just wanted to say, I liked this blog post. It was funny. Keep on posting!

  9. Website Design|Website Development|Web Application Development|Web Design|Web Development|E commerce Website|Best Web Design Company|Website Designing Company|Web Design Solutions|Top Web design companies|Web Design Development|Development Website Company Says:

    Undeniably believe that which you said. Your favorite reason appeared to be on the web the simplest thing to be mindful of. I say to you, I certainly get annoyed at the same time as folks consider issues that they plainly do not recognize about. You controlled to hit the nail upon the top and also defined out the entire thing with no need side effect , folks could take a signal. Will likely be back to get more. Thanks

  10. letter from santa clause Says:

    Throughout this grand design of things you’ll get an A just for effort and hard work. For now I will, no doubt yield to your position.

  11. parajumpers long bear Says:

    You should also discuss expenses like postage, copying fees, etc. Good readers don’t usually realize what they were doing while reading unless someone forces them to reflect on it. Going to a parajumpers ski wear consignment shop is a good way fo yo to get a disconted Billiga Parajumpers item. We find oseCHANELes taking some comfot in the famiia of a time of stong Ameican designes sch as Noman Noe, Bi Bass, Chaes James and Caie McCade. He is known the world over for his wildlife art, but along t

  12. Rayanne Says:

    Hi Sita,I’m seeing blreggos everywhere reporting errors, and there is one common denominator with every person – they have all just updated to IE8.Honestly, ditch it and use Firefox as your browser. IE is so tempremental, even the older versions. That’s why I switched to Firefox. It’s free and easy to download. God blessPeter

  13. Louis Vuitton outlet Says:

    I like just how Louis Vuitton outlet maintain base model on the subject of some of those unique winter weather nights!!!

  14. Make full use of our excellent software packages Says:

    You either see them peeking inside bag of tiles, slacking drawing
    tiles out, or placing words for the board but being not able to
    define them. Unfortunately for cheaters who use anagram solvers, the tool
    would only allow them to have lists of words they’re able to build
    but not necessarily tell them where to place it.
    In order to get to the castle, the plucky plumbers must plow through 8 “worlds.

  15. gucci schoenen Says:

    Put up: [url=http://studio-green.org/wp-content/index2.php?p=oakley-m-frame]oakley m frame[/url]
    A 2 solutions, a single reply: Michelin. [url=http://www.442ndrct.com/sponsor.php?p=michael-kors-snakeskin-purse]michael kors snakeskin purse[/url]
    Microsoft windows Brown lightly mentioned: “Coxhoe Main Education would be the very first school to participate in this specific new motivation and it was a pleasure to go to the particular young people. michael kors hobo
    02/13/2014 14:01:50 AM MSTUpdated: [url=http://studio-green.org/wp-content/index2.php?p=gascan-oakley]gascan oakley[/url]
    Person to love the woman’s, appreciate her a lot more than close friends. [url=http://www.tricivenola.net/brand.php?p=louis-vuitton-tote]louis vuitton tote[/url]
    March Twelve – Nashville, TNMount Zion Baptist Church7594 Aged Peach Blvd, White-colored Streams, Tennessee 37189

  16. tedvfsneick Says:

    [url=http://www.debknuth.com/nike-foamposite-pro.html]Nike Foamposite Pro[/url] Jeff Flake, RAriz., is “personally monitoring the situation, and he has had multiple conversations with the deputy Mexican ambassador,” his office said in a statement… [url=http://www.debknuth.com/nike-foamposite-weatherman.html]Nike Foamposite Weatherman[/url] Ermina Errico, 62, has been ordered to undergo psychological treatment as a condition of probation, according to Union County Prosecutor Theodore Romankow..

    [url=http://www.debknuth.com/nike-air-foamposite.html]Nike Total air Foamposite Max[/url] She is scheduled for sentencing in December on one count of thirddegree neglectResponding officers found the 25yearold wearing sweatpants and a halter top made from a garbage bag.. [url=http://www.debknuth.com/nike-foamposite-pro.html]Nike Air Foamposite Pro[/url] At 5’7″, the young woman weighed just 97 pounds..

    [url=http://www.debknuth.com/nike-foamposite-for-sale.html]Nike Air Foamposite For Sale[/url] A medical examiner later determined she had died from anorexia nervosa and malnutrition, according to the prosecutor’s office.In court today, Emily Errico’s mother admitted to controlling her daughter’s food consumption.Errico said that she controlled the food that was prepared for and given to Emily, said Assistant Prosecutor James Donnelly, who handled the case, in a statement released by the prosecutor’s office.. [url=http://www.debknuth.com/cheap-nike-foamposite.html]Nike Foamposite For Cheap[/url] knew that Emily was suffering from a low body weight and psychological problems..

    [url=http://www.buzzstream.com/blog/the-3-ps-of-great-outreach-emails-personalized-positioned-and-persuasive.html#comment-416218]Gossips, Untruths Then Sports Shoes[/url]
    [url=http://www.bluehostforum.com/member.php?681135-staupeick&s=ecde1a1ef7d53e1e1db71eb769512bc0]Our Own Idiots Self-Help Guide To Shoes Outlined[/url]
    [url=http://www.kppelectroniccar.com/forum/2-%E0%B8%96%E0%B8%B2%E0%B8%A1%E0%B8%95%E0%B8%AD%E0%B8%9A/post.html?do=new]Obtain This Scoop Around Sneakers Before You’re Too Late[/url]
    [url=http://shasta.com/oregon-state-university-players-association/]Our Own Idiot’s Self-Help Guide To Shoes Simplified[/url]

  17. michael kors kids Says:

    03/24/2014 Goal:Thirty-seven:Nineteen Pm PDT [url=http://www.442ndrct.com/sponsors.php?p=michael-kors-large-hamilton-tote]michael kors large hamilton tote[/url]
    03/25/2014 06:44:Ten Evening MDT [url=http://www.442ndrct.com/sponsors.php?p=michael-kors-clearance-handbags]michael kors clearance handbags[/url]
    That Present cards. Eleven, 2014 data file image exhibits celebrity Gwyneth Paltrow, left, as well as her husband, musician Chad Martin for the 3 rd Once-a-year Sean Penn & Pals Enable Haiti Household Event inside Beverly Slopes, Calif. (Colin Young-Wolff/Invision/AP, File) [url=http://www.442ndrct.com/sponsors.php?p=replica-michael-kors]replica michael kors[/url]
    3 Maintain it clean. Please steer clear of obscene, vulgar, lewd, hateful as well as in the bedroom targeted words. [url=http://www.442ndrct.com/sponsors.php?p=michael-kors-discount]michael kors discount[/url]
    Sandra Marlow subsequently referred to as the Police utes Section as well as your ex hubby. [url=http://www.442ndrct.com/sponsors.php?p=michael-kors-sale-handbags]michael kors sale handbags[/url]
    ? Southwest Florida temperature: Ambiance already have shifted in Bonita springs with Monday day and then there are a few bath areas on the way. A few bath areas will probably show up by means of midday, though the nearly all lively time for the actual water will be later on right now in via Tuesday day. [url=http://www.442ndrct.com/sponsors.php?p=michael-kors-hobo-bag]michael kors hobo bag[/url]
    Buy your Concerns Responded Mondy [url=http://www.442ndrct.com/sponsors.php?p=michael-kors-handbags-sale]michael kors handbags sale[/url]
    The disbursement regarding taxes discounts looks like it’s creating a substantial difference in this willingness and talent involving without People in america to enroll in … insurance coverage, Haile explained. [url=http://www.442ndrct.com/sponsors.php?p=discount-michael-kors-handbags]discount michael kors handbags[/url]
    03/19/2014 May:06:30 Pm PDTUpdated:

  18. EdwardNat Says:

    tog0Gdayu9Uu9Oi7B[url=http://www.portaldebeniel.es/aspnet_client/system_web/Michael-Kors-Saat.html]Michael Kors Handbags For Cheap[/url]
    x0Os2Hx2A
    overj9Pthans8Wy4Bj1N[url=http://www.2apublic.com/tiendaonline2009/pages/Mens-Michael-Kors-Watches.html]Fashion Store Online[/url]
    [url=http://www.portaldepliego.es/empresa/jumilla/Michael-Kors-Bag.html]Michael Kors Online Shop Deutschland[/url]
    easyv1Othrough

  19. homepage Says:

    Valuable information. Fortunate me I found your site accidentally,
    and I’m surprised why this twist of fate didn’t came about in advance!
    I bookmarked it.

  20. seo Says:

    We have Office in India at S55-A 2nd Floor Janta Market,
    Rajouri Garden New Delhi – 110026, Indcia Tel. Latedr shortened just too
    Galaxy, this search engine allowed users to browse bby category.
    In the early days of search engines, many website ownhers relied on unscrupulous
    methods to improve their page rank.

  21. nike air max Says:

    pressured Congress and the executive branch of the federal government to tbrce th nike air max 2009 e FBI to open a Mississippi office and make bringing the murderers to justice a priority. Meanwhile, Hoover tapped Schwerner’s father’s telephone to see if he might be a communist! Everyone in eastern Mississippi knew for weeks who had committed the murder and that the Neshoba County deputy WATCHING BIG BROTHER -227 sheriff was involved. No innovative police work was required; the FBI finally apprehended the conspirators after bribing one of them with $30,000 to testify against the others.57 American history textbooks offer a Parkerlike

Leave a Reply