Javascript 仅在使用 <jsp:include> 包含时在页面刷新时执行
Javascript executed only on page refresh when included using <jsp:include>
您好,我使用标签 <jsp:include>
将 html 页面包含到 adf jsff 页面中
<f:facet name="parenContent">
<jsp:include page="www/included.html"></jsp:include>
</f:facet>
页面渲染成功,但是被包含页面中的javascript只在整个页面刷新时执行(手动刷新)。
included.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="grapheditor.css">
</head>
<body class="geEditor">
<script>console.log('loading page');</script>
<h1>Hello</h1>
<script>console.log("check");</script>
</body>
</html>
刷新页面时执行脚本标记。使用
包含 javascript 的情况也是如此
<script type="text/javascript" src="javascript.js"></script>
我试过将脚本标签放在 <head>
和 <body>
中
我需要在第一次加载页面而不刷新时执行js。怎么可能?
更新
我尝试在 <script>
中提供一个不存在的 src 路径
<script type="text/javascript" src="thisFileDoesNotExists.js"></script>
在第一次加载时,它甚至没有尝试加载此文件。在页面刷新时,此文件出现 404 错误。
您可以在启动时调用 javascript 方法。
<af:document>
<af:clientListener method=“nameOfTheJavascriptMethod" type="load"/>
<af:resource type="javascript" source="/customJsCode.js"/> ...
</af:document>
但我不确定当用户刷新浏览器时如何防止它重新执行。
您好,我使用标签 <jsp:include>
<f:facet name="parenContent">
<jsp:include page="www/included.html"></jsp:include>
</f:facet>
页面渲染成功,但是被包含页面中的javascript只在整个页面刷新时执行(手动刷新)。
included.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="grapheditor.css">
</head>
<body class="geEditor">
<script>console.log('loading page');</script>
<h1>Hello</h1>
<script>console.log("check");</script>
</body>
</html>
刷新页面时执行脚本标记。使用
包含 javascript 的情况也是如此<script type="text/javascript" src="javascript.js"></script>
我试过将脚本标签放在 <head>
和 <body>
我需要在第一次加载页面而不刷新时执行js。怎么可能?
更新
我尝试在 <script>
<script type="text/javascript" src="thisFileDoesNotExists.js"></script>
在第一次加载时,它甚至没有尝试加载此文件。在页面刷新时,此文件出现 404 错误。
您可以在启动时调用 javascript 方法。
<af:document>
<af:clientListener method=“nameOfTheJavascriptMethod" type="load"/>
<af:resource type="javascript" source="/customJsCode.js"/> ...
</af:document>
但我不确定当用户刷新浏览器时如何防止它重新执行。