![](/img/trans.png)
[英]Run a function on first time page load not on page refresh in javascript
[英]Run javascript function only for one time (first page load)
我只想运行一次此javascript函数(第一页加载)。 可能吗? 谢谢
<div id="pag">
<script type="text/javascript">
var framekiller = true;
window.onbeforeunload = function () {
if (framekiller) {
return "Click on stay on this page";
}
};
</script>
<iframe scr="http://www.example.com/page-with-javascript-framebuster.html"></iframe>
</div>
您应该在javascript中使用全局变量。
<script type="text/javascript">
window.framekiller = true;
window.onbeforeunload = function () {
if (window.framekiller) {
return "Click on stay on this page";
}
};
</script>
<iframe scr="http://www.example.com/page-with-javascript-framebuster.html"></iframe>
并在其他地方放置另一个JavaScript抓取程序,它将这个变量转换为false,并执行其他操作。例如,打开一个新链接? 要将其恢复为false,请使用:
window.framekiller = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.