Skip to main content
Known Participant
August 27, 2009
Question

attempting to use onRequestStart to execute when a specific page is called up. Please help

  • August 27, 2009
  • 2 replies
  • 2210 views

Hello;

I am trying ot use a little app I have for turning off background music from a dynic web site. It works nice if I reload the page. But I want to pass it off to the application.cfc file and let that file run the code and if a button is clicked, the application should catch it. (If I miss my guess, everytime you click a link in a cf site, the application.cfc is the first page read?) Does that include a page using ajax as a Iframe loader?Anyway. This is my application file code:

<cfcomponent output="false" extends="ProxyApplication">

<cffunction access="public" name="onRequestStart" output="true" returntype="any">
<cfargument name="request" required="true" />

<cfif not IsDefined("cookie.hitbox")>
<embed src='../video/Roller Pop.wav' width="" height="" hidden='true' autostart='true'
loop='true'></embed>
<cfelseif IsDefined("deactivate")>
<cfcookie name="#deactivate#" value="Off" expires="never" domain="myDomain.com"><!--- <cookie defined - stop music> --->
<cfelseif IsDefined("engage")>
<cfcookie name="#engage#" value="On" expires="now" domain="myDomain.com"><!--- <cookie removed music is on> --->
<embed src='../video/Roller Pop.wav' width="" height="" hidden='true' autostart='true'
loop='true'></embed>

</cfif>
</cffunction>
</cfcomponent>

this is part of a larger site. This application file sits in a sub directory pulling the info from the main application.cfc file in the main directory. Now, I want this code to fire every time the page www.mydomain.com/subdirectory/index.cfm file is pulled up.Is this possible this way? If so, how far am I off and can someone help me code this to work?

Thank You!

This topic has been closed for replies.

2 replies

Inspiring
August 28, 2009

The first thing I noticed was:

<cfelseif IsDefined("deactivate")>

Given that this shows up in onRequestStart, when would you ever expect it to return true?

Inspiring
August 28, 2009

Dan Bracuk wrote:

The first thing I noticed was:

<cfelseif IsDefined("deactivate")>

Given that this shows up in onRequestStart, when would you ever expect it to return true?

If it's a URL or form variable, sure.

--

Adam

ilssac
Inspiring
August 27, 2009

I don't know if I can help much with your coding issues, I would need a clearer understanding how you expect that code to work and how it is not working now.

But I can confirm that an applicable Application.cfc or Application.cfm file will be processed before any request received by the ColdFusion server no matter where that request came from, be it normal browser, AJAX xmlhttprequestobject or otherwise.

Known Participant
August 27, 2009

Will it help you if I explain the function I am trying to create in the "non-applcation.cfc" scope?I have a page that has 5 "video streams" you can call up. In the center of the page, it is a picture, if you hit the PLAY VIDEO button, it brings up the main movie. The window it brings it up in is called up using an ajax script that acts like an iframe so the page doesn't have to reload everytime you click on a video.

In the main page it's self, want to have the sound in the background. When someone clicks the "play video" button (that is made out of an image with ajax code in the link) it will disable the bg sound to play the video. When they hit the stop video button, just like the play, it enables the bg sound.The other 4 videos don't need to disable the sound. They will not have sound in them.

So I was trying to make my code work and couldn't think of a way to do it unless it was off on a page on it's own, or an application file so it executes first.

this would be the code if I was to use this without using my application.cfc

<!--- Sound tag that goes in the body--->

<cfif not IsDefined("cookie.hitbox")>
<embed src='../video/Roller Pop.wav' width="" height="" hidden='true' autostart='true'
loop='true'></embed>

</cfif>

<!--- the link to execute the play video and disable the bg sound. This image in the <div> tags loads with the main page. The video loads in place of the image. stop video button, reloads the page and brings back the video.--->

<div id="rightcolumn"><img src="images/picFrameCenter.gif" width="354" height="263" /></div>

<a href="javascript:ajaxpage('movieControl.cfm?deactivate=hitbox', 'rightcolumn');">My image is here</a>

<!--- Execution to turn off the sound page --->

<cfif IsDefined("deactivate")>
<cfcookie name="#deactivate#" value="Off" expires="never"><!--- <cookie defined - stop music> --->
<script>
document.location.href = "soundedit.cfm";
</script>
<cfelseif IsDefined("engage")>
<cfcookie name="#engage#" value="temp" expires="NOW"><!--- <cookie removed music is on> --->
<script>
document.location.href = "soundedit.cfm";
</script>
</cfif>

then you need to refresh the main page and the sound is off.

I'm trying to not have to "reload" the main page with the code on it. I know it sounds hard, but there has to be a way or something close to it to make it work.

is there a way, that I am obviously not thinking of yet to make this work? I know flash would be easier, but I'm not using flash.

thank you

ilssac
Inspiring
August 27, 2009

If I am understanding you correctly, you want the background of the 'main' page to stop when the user clicks one of the 'play' buttons.

If so, none of that is ColdFusion work.  The background music and play button are already running in the client browser.  ColdFusion, running on the sever, is not going to have any affect on a process already running in the browser, unless you tell the browser to replace everything with new content from the server, i.e. a full page refresh.

To do what you want needs to be done in the browser, which is usually JavaScript.  I.E. when the user clicks the button to 'play' the video, that AJAX function that is about to make a request for content on the server, would deactivate the background music currently play.  Conversely, when the 'stop' button is clicked by the user JavaScipt code would start the backgroun music again.

All that work I see in your code, playing with cookies, will only have relevance to future requests, not the request that has already been rendered by the browser.