Wednesday 7 November 2007

Anchor vs JavsScript New Window

So today I was working on a very simple problem.....I thought! Turned out to be a lesson for me and once again one of those usual web development weirdness!

The main problem is this. I want to open up a new browser window at a specific position and specified width and height. However I want the new browser window to look exactly like the client's browser window. By this I mean it should inherit those features of the client's browser e.g. status bar, menu bar, tool bar.

(P.S. - If the client decided NOT to include the status bar in their browser window, the new window that is opened up should follow this too! i.e. this is something I do not know in advance!)


So there are two ways to open up a new window:
  1. Anchor:
    <a href=\"index.html\" target=\"windowName\">
    Glossary index
    </a>
  2. Javascript, window.open():
    window.open(''+self.location,'mywin',
    'left=20,top=20,width=500,height=500,toolbar=yes,resizable=no ');

Now the differences between the two and the problem I encountered:

If you use the JavaScript method with window.open(), you are able to open up a new browser window at a certain position and with a specific dimension. However, problem is the popup window does not inherit the features of the client's browser.

So what about the anchor!? Well yes it does open up a new browser window that inherits the features...but (-.-" yes there's always a but isn't it!)....you won't be able to specify the position and dimension of the browser window!!! Argggghhhhhhhhhhh..........!!!!! (rahhhh!)

You see with the JavaScript method you can specify to include each specific feature or not (see the tool bar feature in the above code). So the best thing I can do is to assume what is in a standard window (of course following a qualified reference i.e. MSDN window.open() ). Base on what is described as the default, I will enable / disable the features when I open up the window via JavaScript.

Of course this is NOT really a solution as I'm only assuming what most client's browser looks like. They can well of course remove the status bar from their browser, which in this case my pop up browser window will not follow. I don't think there are any solutions to my problem right now (which of course is a minor problem)......but perhaps one day when they do improve the HTML spec or JavaScript.....something will be offered in the future for this!

To read more:
pop-up, pop-under windows
Opening a Window