• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

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!

TOPICS
Advanced techniques

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

I was using coldfusion to allow the code to run. If there is no cookie that is set for disable, don't play, and so on.Your way seems more like a solution that would work. You wouldn't happen to know how to make that work wold you?

this is the java / ajax code that operates the iframe function.

<script type="text/javascript">

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

</script>

then the links and window that use it:

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

<!--- this is the only one that needs to disable the sound--->

<a href="javascript:ajaxpage('mainVideo.cfm', 'rightcolumn');">image file here</a>

<!--- the rest just need to open a video--->

<a href="javascript:ajaxpage('mainVideo1.cfm', 'rightcolumn');">image file here</a>

<a href="javascript:ajaxpage('mainVideo2.cfm', 'rightcolumn');">image file here</a>

<a href="javascript:ajaxpage('mainVideo3.cfm', 'rightcolumn');">image file here</a>

<a href="javascript:ajaxpage('mainVideo4.cfm', 'rightcolumn');">image file here</a>

this is the bg sound code:

<embed src='../video/Roller Pop.wav' width="" height="" hidden='true' autostart='true'
loop='true'></embed>

I didn't think of only going to java / ajax. I am really just learning how to properly use ajax. so any help is greatly appreciated.

thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

You need to add an ID and might as well ad a name property to your sound tag.

<embed id="bgsound" name="bgsound" src='../video/Roller Pop.wav' width="" height="" hidden='true' autostart='true'
loop='true'></embed>

Then in the function that starts the movie add a line that stops the sound.  There seems to be two common ways to do this, a stop() function or to clear the source.

document.getElementById("bgsound").stop();

OR

document.getElementById("bgsound").src = "";

Then of course you would do the reverse to start it again in the function that stops the movie.

document.getElementById("bgsound").start();

OR

document.getElementById("bgsound").src="../video/Roller Pop.wav";

None of that is tested, and some of the web sites I used to get the syntac showed some signs that it may be problematic, but that is the idea.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 27, 2009 Aug 27, 2009

Copy link to clipboard

Copied

think I set this up wrong. Is there also an operator missing?

this is what I did:

<head>

<script type="text/javascript">

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

</script>

</head>

<body>

<embed id="bgsound" name="bgsound" src='../video/Roller Pop.wav' width="" height="" hidden='true' autostart='true'
loop='true'></embed>

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

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

</body>

now wouldn't there need to be some kind of ID from the link? I have 5 links using the same "code / window" I only want the main play button to stop the music and the stop button to start it. All the rest don't need to do anyhting to the music. I want it to keep playing.

obviously I am using this wrong, it throws a syntax error.

but do you see what I mean? If I put the java with the stop and start into the java script in the head, how to I make the distinction between the links that are executing it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 28, 2009 Aug 28, 2009

Copy link to clipboard

Copied

What error does it throw?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2009 Aug 28, 2009

Copy link to clipboard

Copied

I tried it 2 ways. 1. was the way I posted on my last post. That error was a sytax error. I used your code in the link that executes the ajax.

the 2nd way I tried it, was in the ajax script it's self. It throw a null not an object error.

this is the script I tried the 2nd time.

<script type="text/javascript">

<!--- the document.getelement is added for sound control. this throws an error that states it is not an object--->

document.getElementById("bgsound").stop();

<!--- end sound control. The rest works the window, it functions 100%--->


var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

</script>

Now I have also been working with some scripts I found on the internet. They aren't working either. this one shows the most promiss. It loads the music, but won't allow me to stop it. I also believe I need to combine this function with the ajax code. Right now, I am trying to execute 2 scripts with one link. No errors, but it still isn't working. The sound also doesn't play in anything but IE with this script. I need it in all browsers. Maybe we can work with this?

<head>
<!-- the ajax script for the iframe--->
<script type="text/javascript">

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

</script>

<head>

<body>

<!--- sound code --->

<SCRIPT LANGUAGE="JavaScript">
<!--
var aySound = new Array();
// Below: source for sound files to be preloaded
aySound[0] = "../video/Roller Pop.wav";
// DO NOT edit below this line

IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += "<EMBED SRC='"+aySound+"' AUTOSTART='TRUE' LOOP='TRUE' HIDDEN='TRUE'>"
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:'';
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }
//-->
</SCRIPT>
<BGSOUND ID="auIEContainer">


<!--- Ajax iframe window. when the page loads, it loads the image in the center--->

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

<!--- this is the link that needs to stop the sound--->
<a href="javascript:ajaxpage('mainVideo.cfm', 'rightcolumn');" onClick="javascript:stopSound(0);">image here</a>

<!--- this is the link that needs to start the sound --->

<a href="index.cfm" onClick="javascript:playSound(0);">my image here</a>

 
<!--- these links don't need to interact with the sound at all --->

<a href="javascript:ajaxpage('mainVideo1.cfm', 'rightcolumn');">image here</a>

<a href="javascript:ajaxpage('mainVideo2.cfm', 'rightcolumn');">image here</a>

<a href="javascript:ajaxpage('mainVideo3.cfm', 'rightcolumn');">image here</a>

<a href="javascript:ajaxpage('mainVideo4.cfm', 'rightcolumn');">image here</a>

</body>

What do you think? I like your idea better though. I really think they need to work together. that means making it one script. correct? Sorry, I have been trying to get this all night and this morning. lol almost out of ideas

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 28, 2009 Aug 28, 2009

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 28, 2009 Aug 28, 2009

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation