14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptでFORMを作って送信するサンプル

Last updated at Posted at 2016-05-11
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script><!--
  window.onload = function() {
    var form = document.createElement('form');
    form.action = 'https://www.google.co.jp/search';
    form.method = 'get';

    var q = document.createElement('input');
    q.value = 'weather';
    q.name = 'q';

    form.appendChild(q);
    document.body.appendChild(form);

    form.submit();
  }
//-->
</script>

</head>
<body>

</body>
</html>

ですが、サーバからのレスポンスが遅いとわかるのですが、レスポンスが返ってくるまでの間、スクリプトで追加した要素がページに追加されて見えてしまいます。これを回避するのに、非表示のDIV要素の中にFORMをおく方法が思いつき、効果があることを確認しました。

それよりも、パラメータを格納する要素をINPUTからHIDDENにするのが手っ取り早い、というか正解なのだと思います。

14
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?