0

when we write

window.open(url,target,..)

a new window is opened.. Can anyone tell me how this is happening internally

oezi
  • 51,017
  • 10
  • 98
  • 115
Asha
  • 11,002
  • 6
  • 44
  • 66
  • 2
    Can you be more specific? I mean, the answer is: The browser opens a window. And yet, I suspect you want more... :-) – T.J. Crowder Jan 27 '11 at 13:00
  • The same thing happen when you double click on the browser icon but window.open() intialize browser window with passed paramter – Shakti Singh Jan 27 '11 at 13:01
  • Put debugger before you call window.open. Try debugging – ashish.chotalia Jan 27 '11 at 13:03
  • it means internally in your browser, once the command window.open(url,target,..) is invoked, the browser take care the rest, if you have a knowledge in C Language, you are able to understand how things work internally, cause almost everything come from C. It will work direct with your operating system, there the things happen. Then: Your code call window.open(url,target,..) the browser invoke the operating system to do the job.. It was what I have learned sometime (years) ago.. – devasia2112 Jan 27 '11 at 13:07
  • @TJ: I am handling the appication were i am given a single instance of browser,In which if external appication calls a new window onclick my application is failling. So was thinking of root cause from which i can redirect any new window to self :) – Asha Jan 27 '11 at 13:29

2 Answers2

2

Here's everything I can think of:

  1. The browser decides whether to ignore your open request depending on its pop-up settings (most browsers will ignore calls to open that aren't in direct response to a user event, like a click). Assuming it allows it:
  2. The browser creates a new window. It may or may not choose to create that window in a new tab, and it may or may not pay any attention to the dimensions and settings you've requested (if you've requested some).
  3. The browser sets the opener property of the new window so it points to the window object of the window that issued the open call.
  4. The browser starts loading the desired resource into the new window (if you've supplied a resource to load).
  5. The window.open call returns a reference to the new window object.

Note that the references that the windows have to each other are to the "external" facet of the relevant window object, which isn't necessarily the same as the actual window object. (Strange but true; it's for security stuff; more in this other StackOverflow question.) So it may be that although you've opened a window, you don't have access to the contents of that window because it's from a different origin.

As to the internals of how browsers actually do it, that's entirely up to the browser implementation. For open source browsers like Firefox and Chrome, you can find out by looking at the source...

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • thank you :) ..for info but as i mentioned my problem in comments, it may be difficult to handle my scenario from the information you have given :)... – Asha Jan 27 '11 at 13:40
  • 1
    @asha: I'm not sure I followed your comment about an external application creating new windows in the single browser instance, doesn't sound like something I've had to deal with in the past. Good luck with it, – T.J. Crowder Jan 27 '11 at 13:46
0

The browser creates a new window, sets the name, dimensions, position, options etc, and then loads the URL into it. Is this what you mean?

mrbellek
  • 2,300
  • 16
  • 20
  • Yes..How is all this happening internally? – Asha Jan 27 '11 at 13:01
  • That depends on the browser and the platform. For Windows, the browser would call the CreateWindowEx() API function and go from there. But this kind of detail is unavailable since most browsers are closed source.. – mrbellek Jan 27 '11 at 13:10
  • Firefox and Chromium (which is almost the same as Chrome) are open source ;) – David Tang Jan 27 '11 at 13:16
  • Alright, then take a look at the Firefox or Chrome source Asha :) – mrbellek Jan 27 '11 at 13:47