2017-01-14 9 views
0

iframeを自動ログインにしようとしています。iframeコードが機能しない

ここに私のコードです。自動的にログインしません。私のコードの問題は何ですか?

<form id="login" target="frame" method="post" action="https://172.16.8.187:6060/NCMContainer.cc"> 
    <input type="hidden" name="username" value="user" /> 
    <input type="hidden" name="password" value="pass" /> 
</form> 
<iframe id="frame" name="frame"></iframe> 
<script type="text/javascript"> 
    // submit the form into iframe for login into remote site 
    document.getElementById('login').submit(); 
    // once you're logged in, change the source url (if needed) 
    var iframe = document.getElementById('frame'); 
    iframe.onload = function() { 
     if (iframe.src != "https://172.16.8.187:6060/NCMContainer.cc") { 
      iframe.src = "https://172.16.8.187:6060/NCMContainer.cc"; 
     } 
    } 
+0

@Gserg編集していただきありがとうございました – jinggoyestrada

+0

'フォームiを送信してくださいリモートサイトにログインするためのnto iframe' - ええ、あなたのコードはまったくそれをしていません - GETメソッドを使ってiframeがロードされています - ログインにはPOSTメソッドが必要です - フォームをiframeに注入し、 iframeにフォームで提出 –

+0

あなたは私にそれのためのガイドコードを教えてくださいできますか?私はちょっと初心者です。とても残念です。 – jinggoyestrada

答えて

0

あなたの主なHTMLは次のようになります。

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8" /><meta charset="utf-8" /> 
    <title>Numpty</title> 
    </head> 
    <body> 
    <iframe src="frame.html"></iframe> 
    </body> 
</html> 

は、今のiframeがにログインされます。この

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8" /><meta charset="utf-8" /> 
    </head> 
    <body> 
    <form id="login" method="post" action="https://172.16.8.187:6060/NCMContainer.cc"> 
     <input type="hidden" name="username" value="user" /> 
     <input type="hidden" name="password" value="pass" /> 
    </form> 
    <script type="text/javascript"> 
     document.getElementById('login').submit(); 
    </script> 
    </body> 
</html> 

のように見えることができ、新しいファイル、frame.htmlを作成しますhttps://172.16.8.187:6060/

+0

それはページに行きますが、ログインしていません。何か不足していますか?サイトのユーザー名とパスワードのフィールドはまだ空白です。 – jinggoyestrada

+0

デベロッパーツールのコンソールやネットワークタブを確認してください - 'https://172.16.8.187:6060/NCMContainer.cc'へのPOSTは起こっていますか?もしそうでなければ、私のコードに問題があります。もしそうなら、おそらく 'https://172.16.8.187:6060/NCMContainer.cc'はあなたのmain.htmlがどのホストからでもフォームを提出するのを好まないからです –

関連する問題