Asha
Asha

Reputation: 11232

what exactly happens when we write window.open()?

when we write

window.open(url,target,..)

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

Upvotes: 0

Views: 206

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1075755

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...

Upvotes: 2

mrbellek
mrbellek

Reputation: 2300

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?

Upvotes: 0

Related Questions