Help me with javascript

Help me with javascript

I have one file have name: 1.html writed code:
<HEAD>
<TITLE>WINDOWS</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function openWindow(url,name) {
popupWin = window.open(url, name, "scrollbars=yes,width=800, heigth=200 ");
}
function m(a) {
popupWin = alert('Click ok');
}
</SCRIPT>
</HEAD>
<BODY>
<a name="123" href="javascript:m(this.a)">oPen</a>,<br>
<input type="button" value="-link-" onclick="m(this.a)">

</BODY>
</HTML>
-------------------
i want to write one file with name 2.html
can control fuction m(a) of file 1.html
when open 2.html will run m(a) and show "click ok"
Help me! Thanks everyone

i don’t know that u use firefox,sorry,it’s my mistake.
u can try as following.It can be run on IE and Firefox after my test.
2.html

<html>
<head>
</head>
<body>
<iframe style=“visibility:hidden” src=“1.html” id=“ifm”></iframe>
<input type=“button” value=“button” onclick=“document.getElementById(‘ifm’).contentWindow.m();” />
</body>
</html>

Oh, thanks! your file can run on IE but don’t run on FIREFOX

Oh, thanks u! But when click button on 2.html , the function of 1.html don’t Run :frowning:

Oh, thanks u! But when click button on 2.html , the function of 1.html don’t Run

I try check again. Resulf is : something the function called but something can’t call this function !:wink:

Ok, thanks u very much! But when i upload to host then don’t run :frowning:
I upload file to host: http://muangay123.com/2.html and http://muangay123.com/1.html

But the function don’t run :frowning:
Help me ! Thanks everybody!

I can use to investigate the function from the file. html not. because if it is. js, you can use the src = “http://example/file.js.” but if a file is “. html” from a different page, you can call it?

first,i think this is not a right design philosophy.
u can try to use the following way.
1.html

<HEAD>
<TITLE>WINDOWS</TITLE>
<SCRIPT LANGUAGE=“JavaScript”>
function openWindow(url,name) {
popupWin = window.open(url, name, “scrollbars=yes,width=800, heigth=200 “);
}
function m(a) {
popupWin = alert(‘Click ok’);
}
</SCRIPT>
</HEAD>
<BODY>
<a name=“123” href=“javascript:m(this.a)”>oPen</a>,<br>
<input type=“button” value=”-link-” onclick=“m(this.a)”>
</BODY>
</HTML>

2.html

<html>
<head>
</head>
<body>
<iframe style=“visibility:hidden” src=“1.html” id=“ifm”></iframe>
<input type=“button” value=“button” onclick=“ifm.m();” />
</body>
</html>

As I understand it you want a button on 1.html to fire an alert on 2.html. The following script does that, but you need to move the new window away from the main window so that the alert doesn’t hide behind the window holding 1.html.

The function with the alert is part of the the new page 2.html.

// ===== 1.html ================

<html>

<head>
<title>This is 1.html</title>
<script type=“text/JavaScript”>
<!–
// global ref used to communicate with new window
var popupWin=null;
//
// open new window
function openWindow(urlA,nameA)
{ // check to see if popupWin already exists
if(!popupWin || popupWin.closed)
{ popupWin=window.open(urlA, nameA, “scrollbars=yes,width=200,height=200”);
}
else
{ popupWin.focus();
}
}
// ======== end open window =========
//–>
</script>
<style type=“text/css”>
<!–
#main { position:absolute; top:100px; left:100px; width:100px; height:100px; text-align:left; }
#main p { margin-top:0px; margin-bottom:10px; }
–>
</style>
</head>

<body>

<div id=“main”>
<p class=“zz”><a name=“123” href=“javascript: openWindow(‘2.html’,‘winA’)”>Open</a></p>
<p><input type=“button” value=“-link-” onclick=“window.popupWin.m()”>
</div>
<!-- end main –>

</body>

</html>

// ======= this is 2.html ================

<html>

<head>

<title>This is 2.html</title>
<script type=“text/javascript”>
<!–
function m()
{ alert(‘Click ok’);
}
//–>
</script>
</head>

<body>

<p>This is your new window. Click the link in the first window to fire the alert
in this window</p>

</body>

</html>

Move the JavaScript into a separate file so you can link it into both pages.

i visited your site:http://muangay123.com/2.html ,then i found that there was something wrong with the value of src,check your code

<iframe style=“visibility:hidden” src=“http://www.muangay123.com/1.html” id=“ifm”></iframe>

http://www.muangay123.com/1.html” and “http://muangay123.com/2.html” is not in the same domain,so you do not have the authority to call the function

Why do you want to call a function in a html file on another website. Is the other website someone else’s website or is it yours?

------>
ok!Thanks very much u! u undestanded think of me! But i want call a function from web another.So i can’t call
Example: function showAlert() input at http://example.com/file_1.html
And i can’t change this.
Can u help me call function showAlert from another website? Thanks!

file_1 (parent window) contains the function you want to run.

When you open file_2 (child window), the function in the parent window will be automatically called.

file_1.htm

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
 
function showAlert() {
 alert("Function from file_1 was called");
}
 
</script>
</head>
<body>
 
<h1> This is file 1</h1>
 
<p>
 <a href="#" onclick="window.open('file_2.htm'); return false;">Open file 2</a>
</p>
 
</body>
</html>

file_2.htm

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
 
window.onload=function() {
    var openerWin = window.opener;
    openerWin.focus();
    openerWin.showAlert();
}
 
</script>
</head>
<body>
 
<h1> This is file 2</h1>

</body>
</html>

I want to use a this page to control a another page.you help yourselves!