Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-deprecated equivalent of <form target="...">

I want to achieve the same as...

window.open('lalala.php', 'lalala', '...');

But I want to send a HTTP POST request instead of a HTTP GET request. Thus, I'm using the following:

$('<form/>').attr('action', 'lalala.php')
            .attr('target', 'lalala')      // w3schools.org says this is deprecated
            .attr('method', 'post')
            .append(hiddenParam('param1', param1))
            .append(hiddenParam('param2', param2))
            .submit().remove();

// hiddenParam is a function I created that returns an input tag
// the type attribute set to hidden,
// the id attribute set to the first parameter,
// and the value attribute set to the second parameter

However, the target attribute is deprecated. Is there any way to achieve what I'm trying to do by non-deprecated means?

like image 378
pyon Avatar asked Jan 28 '11 13:01

pyon


2 Answers

Use target — it isn't deprecated.

like image 72
Quentin Avatar answered Oct 30 '22 09:10

Quentin


  1. target is only missing in strict doctypes. It is not deprecated. The simplest solution is to use a transitional doctype.
  2. All browsers that I am aware of do the right thing, even if you use a strict doctype.
  3. If you must use a strict doctype, and you care that much about validation, then you can extend the doctype definition:

Just be aware of this 'bug' in just about every browser. The solution is to serve your XHTML as application/xhtml+xml, but this will cause IE to blow up, so you need to sniff for that browser before determining the content type. It's essentially one giant hack for a tiny check box on a validation form. It's usually a lot simpler to just use a transitional doctype.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [ <!ATTLIST form target CDATA #IMPLIED> ]>
like image 30
Matthew Scharley Avatar answered Oct 30 '22 09:10

Matthew Scharley