Mitali
Mitali

Reputation: 111

How to include JavaScript in onRequestStart() of Application.cfc

I have an onRequestStart() as follows

<cffunction name="onRequestStart" access="public" returntype="boolean" output="false" hint="initializes the request">
    <cfif deployment.DBFlag eq 'Live' >
        <cfset REQUEST.DataSource = deployment.LiveDSN>
    <cfelse>
        <cfset REQUEST.DataSource = deployment.TestDSN>
    </cfif>
    <cfset REQUEST.ServerBasePath = deployment.ServerBasePath>
    <cfif not listContains(APPLICATION.ListOfFile,Trim(cgi.script_name))>
        <cfif not isDefined("SESSION.UID")>
            <cflogout>
            <cflocation url="/rpnet-ROI/loginform.cfm" addtoken="no">
        </cfif>
    </cfif>

    <!--- Return true so the page can process. --->
    <cfreturn true />
</cffunction>

I need to reload my page once the session id is not defined. Is it possible to include javascript in Application.cfc? If yes, how can we do that else do we need to include a cfm file containing javascript code in it.

The code I need to include in the JavaScript is:

<script>parent.location.reload(true);</script>

Upvotes: 1

Views: 644

Answers (2)

Carl Von Stetten
Carl Von Stetten

Reputation: 1149

Put the parent.location.reload(true); into the login page's window.onload() method, wrapped within a check to see if you are actually inside an iframe (if the login page can also be called outside of an iframe).

Upvotes: 0

Scott Stroz
Scott Stroz

Reputation: 7519

No, it is not possible to include JavaScript in Application.cfc. The code inside the methods of Application.cfc occur server side and has no way to call code on the client side. Specifically, onRequestStart() runs once the request is made to the server. There is no response from the server at this point, so there is nothing for the client to be able to display/act on.

Upvotes: 5

Related Questions