Is there any way to reuse a window with the target form?

Asked

Viewed 97 times

1

We know that by property target HTML form we can tell if the request window will open in the same window or in a new.

When using target="_blank" a new window is opened, it makes sense even by the name _blank, :-)

We have the following options

  • _self: Load the response in the same browsing context as the current one. This is the default value if the attribute is not specified.

  • _blank: Load the response in a new incognito context.

  • _parent: Loads the answer in the context of the current parent navigation. If there is no parent, this option has the same behavior as _self.

  • _top: Load the response in the context of root navigation (i.e., the browsing context that is ancestral to the current one and has no parent). If there is no parent, this option has the same behavior as _self.

But I came up with a question that I did not find on the web, at least in a clear way. I could use the window.open and determine the same window always, but then we have the problem of blocking "popups" :-(

Also in my layout I didn’t see how to use a <iframe>, which would be another window reuse option, as I need it to be shown in another window.

Common example:

<form id="MeuForm" action="pagina.php" target="_blank">
  <input type="text" name="pesquisa" value=""/>
  <input type="submit" value="Relatorio"/>
</form>

Sending the form will open a new tab in the browser at each request, "filling" windows to the user screen and consuming unnecessary resources, because the need is that it sees only one report at a time.

Is it possible to reuse the same window (which has already been opened in _blank) to display the next results of a request for a <form>?

  • I can’t believe I did it, :-) after reading about the target I ended up doing a test on my code and decided to put target="report" on the property... and to my surprise (but not so much) the request is always open in the same window... is that a behavior of all browsers? Tested in Chrome, Firefox and Safari, the problem with Safari is that it doesn’t bring the window for shipping like Firefox and Chrome.

1 answer

1


The attribute target defines the browsing context of the action. In a form, this attribute will define the browsing context after submission of the form.

As we already know, there are some special names - starting with the character LOW LINE (U+005F) - how _blank, _self, _parent, or _top. You can learn more about their behavior here.

However, the specification HTML 5 still allows arbitrary names to be used to define other browsing contexts, as long as they do not start with the character denoting the special names, that is, LOW LINE (U+005F).

Simply (see the table of specification to learn more), when you define a name, the behavior will be as follows:

  • In case the name is not yet used, the effect will be the same as _blank, that is to create a new browsing context.

  • If the name has already been used, the effect will be the same as _self, that is, submit the form in the context already created (provided it has the same name).

There are other cases, also placed in the table:

Tabela que especifica os nomes do atributo target

Source.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.