admin管理员组文章数量:1414614
On the first page:
<button type="button" onclick="myFunction()">click</button>
Then on another page:
myFunction() {
alert("working");
};
This is the receiving page.
- all the basic tags
<script>
function alert() {
alert("The Link Has Been Successful");
}
</script>
The question is: How do I call the other function on the other page to alert that page <button onclick="????">
?
<body>
<button onclick="???" type="button">Alert on the other page</button>
</body>
On the first page:
<button type="button" onclick="myFunction()">click</button>
Then on another page:
myFunction() {
alert("working");
};
This is the receiving page.
- all the basic tags
<script>
function alert() {
alert("The Link Has Been Successful");
}
</script>
The question is: How do I call the other function on the other page to alert that page <button onclick="????">
?
<body>
<button onclick="???" type="button">Alert on the other page</button>
</body>
Share
Improve this question
edited Jun 9, 2021 at 12:19
BarryCap
3363 silver badges12 bronze badges
asked Nov 10, 2012 at 18:38
LouisdewarLouisdewar
774 silver badges9 bronze badges
6
- Please explain in more detail what the goal is so it is clear to all exactly what behavior you are looking for. – charlietfl Commented Nov 10, 2012 at 18:42
- I was trying to activate a function if i was on one page and the function was on another. – Louisdewar Commented Nov 10, 2012 at 18:44
- 1 what does "function on another page" mean? Concept needs to be explained what you are expecting to happen. If it means do something in other page when that page loads after a specific link is clicked...you need to explain that behavior in more detail. Otherwise it could mean you are trying to do something impossible. We can't read minds – charlietfl Commented Nov 10, 2012 at 18:50
- Say you had a website hosted and you had these two files in the same folder and if a user pressed a button on one page it activated something like an alert on another. For sake we can call the one we're having the button on 1.html and the alarm 2.html – Louisdewar Commented Nov 10, 2012 at 18:54
- Apparently it's impossible but maybe you have some way around it even with a different code if you do, do a different code please show it and if you could explain it, thanks. – Louisdewar Commented Nov 10, 2012 at 18:57
3 Answers
Reset to default 2Call a function in one page when the function is on another page
That is not possible. The definition of said function
must be present on the current page for it to be executed.
The standard approach is to extract your function into it's own (or global) JavaScript file. Then reference it on pages that need to use it.
You can place all your global functions etc in a .js text file and then on all pages that need to call any of these routines you should declare it like this...
<script src="myglobals.js" type="text/javascript"></script>
Now you can access your global functions and variables. Good luck!
You do not need to link 2 pages together you just need to link them to your index.html by using: and then js will do all the work for you!
Hope This Helps!
LucaSpeedStack
本文标签: javascriptCall a function in one page when the function is on another pageStack Overflow
版权声明:本文标题:javascript - Call a function in one page when the function is on another page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745172897a2646082.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论