-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.

2
  • 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. Commented Mar 4, 2019 at 14:04
  • If one of the pages is in an iframe, you can call a function in the iframe from the other page. Commented May 21, 2022 at 13:51

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.