6

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?

7
  • 11
    Don't always believe w3schools Jan 28, 2011 at 13:39
  • 6
    Never believe w3schools until you've seen supporting evidence from a source that is actually trustworthy.
    – Quentin
    Jan 28, 2011 at 13:51
  • So, which is a reliable source? (And, btw, could the W3C sue this w3schools guys?)
    – isekaijin
    Jan 28, 2011 at 13:54
  • 5
    For reference (as I came here from Google in search of an answer) "The target attribute on the a element was deprecated in a previous version of HTML, but is no longer deprecated, as it useful in Web applications, particularly in combination with the iframe element." http://dev.w3.org/html5/markup/a.html
    – Paul C
    Jul 2, 2012 at 15:33
  • 1
    W3Schools === misinformation. More info: W3Fools
    – tatlar
    Jan 30, 2013 at 16:38

3 Answers 3

6

Use target — it isn't deprecated.

8
  • These guys say it is: w3schools.com/TAGS/att_form_target.asp . But they use ASP, so they can't be serious, right?
    – isekaijin
    Jan 28, 2011 at 13:48
  • 7
    They are wrong (as usual: w3fools.com ) I challenge you to find a D in the Deprecated column for the target attribute at w3.org/TR/html4/index/attributes.html or a reference in any other official specification.
    – Quentin
    Jan 28, 2011 at 13:49
  • Thanks. Even though it makes me feel stupid to acknowledge I learnt everything I know about Web development from w3schools.org.
    – isekaijin
    Jan 28, 2011 at 13:51
  • 2
    @Floern — "doesn't exist" and "deprecated" are two different things. There isn't a 1:1 correlation between them.
    – Quentin
    Jan 28, 2011 at 14:04
  • 1
    @Liam — they improved things from being "Sheer horror" to "Pretty rubbish". Still best avoided.
    – Quentin
    Feb 16, 2018 at 11:57
5
  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> ]>
7
  • 3
    target is not deprecated anywhere. It just doesn't appear in strict doctypes.
    – Quentin
    Jan 28, 2011 at 13:35
  • What does [ <!ATTLIST form target CDATA #IMPLIED> ] do?
    – isekaijin
    Jan 28, 2011 at 13:37
  • @Eduardo in theory, it tells your browser that there's an extra attribute on the <form> element called target. In practise, it causes your browser to throw up (unless you happen to be using Opera). Jan 28, 2011 at 13:38
  • @Eduardo It's standard DTD language. If you actually go check out the XHTML DTD at http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd you'll see all sort of similar looking statements. Jan 28, 2011 at 13:39
  • 1
    @Matthew: No way I'm going to go through all of this, but thanks anyway! (I don't know why fairies don't write a standards-compliant browser that runs on every operating system...)
    – isekaijin
    Jan 28, 2011 at 13:46
0

Add

<form target="lalala" ...></form>
1
  • That will target a new, unnamed, window and not the one opened with specific arguments.
    – Quentin
    Jan 28, 2011 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.