2016-10-20 6 views
-1

javascriptの を使用して、別のHTMLページへの1つのHTMLページからの値の渡し、以下の私のコードです: ・ファーストページhtml1.htmlとして:Javaスクリプトを使用すると、あるHTMLページから別のHTMLページに値を渡すことはできますか?

<!DOCTYPE html> 
    <html> 
    <head> 
    <script> 
     function newDoc() 
     { 
     window.location.assign("html2.html"); 
     } 
    </script> 
    </head> 
     <body> 
     <input type="button" value="submit" onclick="newDoc()"> 
     </body> 
    </html> 

そしてhtml2.htmlとしての第2のHTMLコード:

<!DOCTYPE html> 
    <html> 
    <head> 
     <script> 
     function newDoc() 
     { 
     window.location.assign("html1.html"); 
     } 
     </script> 
    </head> 
     <body> 
     <input type="button" value="submit" onclick="newDoc()"> 
     </body> 
    </html> 
+0

[localStorage](http://www.w3schools.com/HTML/html5_webstorage.asp)に値を格納しようとする可能性があります。 – matox

+1

Cookieを使用しますか? – evolutionxbox

+0

単にPOSTまたはGETを使用するのはなぜですか? – jogoe

答えて

0

JavaScriptでは、window.locationオブジェクトにはsearch属性があります。したがって、お住まいの地域がhttp://example.com/html1.html?foo=barの場合、window.location.search?foo=barconsole.log(window.location))です。私たちは、いくつかの特定のdivにファイルをロードするためにjqueryの機能を使用することができます

インラインフレーム

<body> 

     <iframe src="html2.html"> 

     </iframe> 

    </body> 
を使用して1つのHTMLファイルに他のファイルを読み込むことができ、HTMLで How can I get query string values in JavaScript?

1

search文字列を解析する方法

 <script> 
     $(function(){ 
     $('#header').load("header2.html"); 
     }); 
    </script> 
0

あなたが渡したい変数は、多分のlocalStorage /のsessionStorageまたはクッキーに保存するほうが良いでしょう、あなたのアプリケーションのために重要である場合。

関連する問題