简体   繁体   English

在页面上运行javascript加载/关闭

[英]running javascript on page load/close

I am a total amateur to javascripts. 我是javascript爱好者。 I have the scripts in this form. 我有这种形式的脚本。

<!-- BEGIN code-->
<script type="text/javascript">a_b='2385y283yf28332';</script>
<script type="text/javascript" src="http://somewebsite.com/jsclients
/jac.js"charset="utf-8"></script>
<!-- END Code -->

Currently, in order for the code to be executed (the code produces a pop up) a click needs to occur on my web page. 当前,为了执行该代码(该代码产生一个弹出窗口),需要在我的网页上单击一下。

I wanted to know, if theres some method which will execute the code when user lands on my website (without clicking anywhere on my site) 我想知道,是否有某种方法可以在用户登陆我的网站时执行代码(无需在我的网站上单击任何位置)

Thanks for any help! 谢谢你的帮助!

<html>
<head>
<script>
function yourFunction()
{
alert("Page loaded!");
}
</script>
</head>
<body onload="yourFunction()">
</body>
</html>

this will sure works fine.try this. 这一定可以正常工作。

Simply in your javascript you can put 只需在您的JavaScript中,您就可以

document.onload(function(){
    //DO STUFF HERE
});

And for when your page unloads, 而当您的页面卸载时,

document.unload(function(){
    //DO STUFF HERE
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM