-4

for Example I have a html page :

a.html

and I have another html page :

b.html

and a button in a.html

<button id="btnsayhello" onClick="SayHello()">Say Hello</button>

and a function in a.html script tag :

function SayHello() {
alert("Hello");

}

and a function in b.html script tag :

function down(sec) {
    setTimeout("location.href='" + "a.html" + "'", sec * 1000);
    $("#btnsayhello").click();

}

this code is not correct , but how Can I do this ? I want to click a button of a html page from another html page.

  • you should rather use one script file on both pages and pass parameters across the pages, maybe that was what you intended initially.. since in HTML, more than one or more pages can utilize the same external js or css file. – Ande Caleb Mar 04 '19 at 14:04
  • If one of the pages is in an iframe, you can [call a function in the iframe](https://stackoverflow.com/questions/1600488/calling-javascript-function-in-iframe) from the other page. – Anderson Green May 21 '22 at 13:51

1 Answers1

1

Put your javascript in an external file (like scripts.js) and include it in each of your html files:

<script src="path/to/scripts.js"></script>
Kévin Bibollet
  • 3,573
  • 1
  • 15
  • 33