English 中文(简体)
XMLHttpRequest - Change Value with Access ElementById
原标题:XMLHttpRequest - Change Value with getElementById
  • 时间:2011-11-05 19:44:40
  •  标签:
  • javascript

I want the button on the second page to change the value of the button in the first page,this is my code:

FILE 1: Index.html (page one):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Eran Exercise</title>
<link rel="stylesheet" type="text/css" href="design.css" />
<script src="new_file.js"></script>

</head>
<body>

    <div class="wrapper">

        <form> 
<input type="button" id="id200" value="New Window!" onClick="window.open( page2.html , mywindow , width=400,height=200 )"> 

</form> 

                    </div>


</body>
</html>

FILE2:new_file.js(js file)

function changeLink()
{
var someOtherName="after click";

xmlhttp=new XMLHttpRequest();

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("id200").value = someOtherName;
}
 }
xmlhttp.open("GET","index.php");
xmlhttp.send();
}

FILE 3:page2.html (page two)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<script src="new_file.js"></script>
 </head>

<body>
<input type="button" id="id100" onclick="changeLink()" value="Change link">
</body>
</html> 

感谢!

问题回答

替换

document.getElementById("id200").value = someOtherName;

页: 1

window.opener.document.getElementById("id200").value = someOtherName;
  1. 先前的答复

    但它只在同一领域开展工作,或者如果服务器发送特别头盔的话。

  2. you can use cookies or local storage

    除非在第二页上注明,并放在第一页。

    also you can use php script and get/save the state from/to there

  3. 页: 1

    and never use sincronious requests





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签