Writing to a newly opened window in IE when the parent window specifies a document.domain

August 20th, 2010

I’ve run into this problem before. IE considers a new window (or frame) opened with Javascript to be in a different domain than that of the window that opened it. Usually this won’t cause a problem, but if the parent window has document.domain explicitly set, then IE won’t allow the two windows to communicate with one another.

How I solved it before was to initially set the location on the new window to a dummy file on the same server as the parent window. This dummy file would be empty with the exception of a Javascript block that would set the document.domain.

However, this solution only works if you’re in control of the site loaded in the parent window.

My current project is a little more tricky. I’ve got a bookmarklet that creates the new window, and this bookmarklet can be clicked on while you’re visiting any site. The javascript in the bookmarklet is executed in the context of the page currently being viewed. The first thing my bookmarklet does is open a new window and then tries to write to it.

It wasn’t working on sites with document.domain set. I would get the dreaded “Access denied” error message.

I was pretty sure it was going to be impossible for me to get around this. I stumbled on a post on stackoverflow that gave me hope, though. Unfortunately, the posted solution didn’t work for me (though to be fair, the question never mentioned document.domain). However, it did give me an idea: set the window location to a Javascript URL that sets the document.domain. And thus here is my solution:

var w = window.open();
try {
   w.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
      + "<html><head></head><body>Test</body></html>");
} catch(e) {
   // If the first call fails because document.domain is set, try again with document.domain
   w.location = "javascript:document.write('"
      + "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
   + "<html><head><script type=\”text/javascript\”>document.domain=\”" + document.domain + “\”</script></head><body></body></html>’);document.close()”;
   w.document.body.innerHTML = “Test”;

In Internet Explorer, the window.resize event is fired when any element on the page is resized

March 5th, 2010

What’s wrong with IE developers? A window.resize event should happen if the user resizes the window, not if elements on the page change in size! The actual window isn’t changing sizes! And this weird behavior persists even in IE8?

Note: you might not see it unless you’re using a DOCTYPE. But you should be using a DOCTYPE, so…

Unfortunately even the jquery library doesn’t compensate for this.

It looks like all you can really do is just manually test yourself to see if the window dimensions have changed (see Stack Overflow for an example solution).

WoW Armory update

January 14th, 2010

Nerdy, maybe, but it’s cool to be able to pose your World of Warcraft characters from a webpage!


February 5th, 2008

Not sure why, but lately nothing has been quite as good to listen to as the music of Rimsky-Korsakov. It puts me in a good mood, and at work it’s making me more productive. Maybe it’s the energy and the brightness, helping me out when I feel tired or blah.

Rimsky-Korsakov: Great Orchestral Works

New job: gather.com

October 18th, 2007

I haven’t updated my blog in forever, but just thought I’d post that I’ve started a new job recently, at gather.com. My title here is “Web UI Developer”. I probably won’t be doing much Java coding at all - mostly HTML/CSS/Javascript in the context of JSPs. At least that’s how they’ve done it in the past. They’re hoping to move to using a better web architecture, like Struts. In that case, I might be getting into Java code a little bit more. Guess we’ll see how that goes. It’s kind of nice to not have to worry about the back-end much, though. :)

Gather is definitely a larger company than DigitalAdvisor (6 people at its largest), but it’s still considered a start-up, I think. There are maybe 40-50 people here, not sure exactly how many.

The site itself has a pretty large and loyal community, and they’re hoping to grow a lot more. The site is a little confusing to a first-time user, I think, but there are plans for working on creating a more intuitive navigation and working on the homepage and such.

The only drawback I’ve found so far is working downtown, because my commute is longer. I’ve been taking the bus to Harvard Square and then the subway from Harvard to Downtown Crossing. It’s been taking me around 40-45 minutes, and I’m more used to 15-25. I need to go to the library to stock up on books to read while commuting…

Keep informed on Gather.com! Content ranges from politics to cooking, and we earn Gather Points™ or cash for using the site!View my content here: jennifer76

Note to self: use trimDirectiveWhitespaces in JSPs after switching to Tomcat 6

April 11th, 2007

So JSPs have the annoying property of preserving all whitespace from the source JSP file and outputting it. As soon as your JSP gets at all complex, with conditional logic, variables being set, and so on, you’ll find your HTML source output gets filled more and more with blank lines.

JSP 2.1 to the rescue! Now there’s a handy page directive you can put at the top of your JSP file:

<%@ page trimDirectiveWhitespaces="true" %>

The only problem is that Tomcat 5.5 doesn’t support it, and that’s what we’re using right now. I guess Tomcat 6 is still in development.

So this blog posting is just to remind myself to use it in the future when it becomes available to us.

And yes, I know it has been forever and forever since I last posted.