-2

Hi I have included an html page into an adf jsff page using the tag <jsp:include>

<f:facet name="parenContent">
            <jsp:include page="www/included.html"></jsp:include>
</f:facet>

The page is rendered successfully, but the javascripts inside the included page is executed only on the refresh of the whole page (by manually refreshing).

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>

When refreshed the page the script tag is executed. The same is the case with javascript included using

<script type="text/javascript" src="javascript.js"></script>

I have tried placing the script tag in both <head> and <body>

I need to execute the js when the first time the page is loaded without a refresh. How is it possible?

Update

I tried giving a non existing path to the src in <script>

<script type="text/javascript" src="thisFileDoesNotExists.js"></script>

On the first load it is not even trying to load this file. On page refresh it is giving 404 error for this file.

Rakesh Nair
  • 1,083
  • 3
  • 21
  • 30
  • Is what is expected to do, jsp tags are executed in server side, and javascript code in client side, after rendering the generated html. – Francisco Valle Nov 16 '17 at 07:12
  • @FranciscoValle Is there any way I could execute the js while the page is loaded for the first time. – Rakesh Nair Nov 16 '17 at 07:14
  • Try to use this sintax: (function() { ...})(); inside a script tag. It will execute after rendering. THis link must be helpfull https://stackoverflow.com/questions/9899372/pure-javascript-equivalent-of-jquerys-ready-how-to-call-a-function-when-t – Francisco Valle Nov 16 '17 at 07:20
  • tried that not working. None of the js is working untill a page refresh – Rakesh Nair Nov 16 '17 at 07:26
  • Javascript is executed after rendering the page in a client. Is what is expected to do, if you dont attach javascript to events on client side it will not be executed again as html is not rendered again in browser. I dont know what result you are expecting... – Francisco Valle Nov 16 '17 at 07:32
  • I did the functionality by adding all the js resources in the main page. And is working – Rakesh Nair Nov 16 '17 at 09:20

1 Answers1

1

You can call a javascript method on startup.

<af:document>
 <af:clientListener method=“nameOfTheJavascriptMethod" type="load"/>
<af:resource type="javascript" source="/customJsCode.js"/> ...
</af:document>

But I am not sure how can you prevent that from re-executing when user refreshes the browser.

Florin Marcus
  • 1,647
  • 1
  • 10
  • 11