Javascript Redirect Magic

The comment redirection I’m doing doesn’t work with Movable Type out of the box. The problem is that you can return either to the page that submitted the comment (static == 1) or to the comment listing (static != 1). Since I had a pop-up window in the mix, neither really worked all that well.

My comment listing template is very bare – it is, in fact, only a form for leaving the comment. Meanwhile, redirecting back to the entry page is ugly because of the pop-up window. It just doesn’t fit quite right. So I needed a new solution.

I dug through the Movable Type code a bit, and found the reload_opener.tmpl file. This is the template used to provide a confirmation for deleting things like comments from the administrative interface of Movable Type. And therein I found the answer.

The code in this template first checks to see if there is a location of the calling window (window.opener.location in Javascript-speak). If there is, it then loads a URL in the calling window and then closes the current window (the pop-up).

I simply took this code, modified it a bit for my own needs by changing the loading of a URL to the reload method instead, and added it to the bottom of the comment posting routine in Comments.pm. This means that, instead of redirecting to one of the other choices, it goes to the calling window instead, then closes the pop-up. Problem solved.


Posted

in