Link to home
Start Free TrialLog in
Avatar of ecpeel
ecpeel

asked on

instead of history.go

Hi [having a brain freeze],

On the page that sends to the item details page (display search results) are the search results.
On this page I trigger a Survey and set a cookie to say the Survey has been taken (onclick select for details).
On an item details page we're using a history.go(-1) as a "back" button.

Problem: if you use the back button the page doesn't refresh to run the logic to enable or disable the code to trigger the survey. Of course a fresh search triggers the code.

any ideas about how to get that page to reload and run this code?

Thanks in advance
Avatar of gdemaria
gdemaria
Flag of United States of America image

Use cflocation to redirect to the page
Avatar of ecpeel
ecpeel

ASKER

Hi gdmaria,
I don't think that will work. The page where the search critieria was before itemsdisplay page.
I'll need to activate the "check" as a call to a page external to the stateless page so that regardless it always does a validation.
It's been mentioned that it could be a ajax call the page that holds the javascript function and the cflogic.
I guess something like inclick = myFunc
and inside of myFunc is the call to the validation data
 $ajax(url:validationcode.cfm);

something like that ...
> I'll need to activate the "check" as a call to a page external to the stateless page so that regardless it always does a validation.

sorry, this is unclear

Is the validation you are performing server side?  (Coldfusion?)

If so, what is triggering that validation, a particular form post?

If so, you can form post back from your itemDisplay page to your itemSearch page.

But, personally, I would never reply on using back or go(-1) to navigate between pages.
Avatar of ecpeel

ASKER

the validation is server side and looks like this:

function showSearchSurvey(){
<cfif structkeyexists(cookie,'searchResultsSurvey.clickedSurvey')>
	<cfset variables.killSurvey = 1>
	<cfelse>
	<cfset variables.killSurvey = 0>
	</cfif>
	<cfif variables.killSurvey EQ 0>
window.open('https://www.surveymonkey.com', 'invitationwindow', 'height=350,width=500,scrollbars=yes,resizable=yes,status=yes');			
<cfcookie name="searchResultsSurvey.clickedSurvey" value="Yes"expires="never" 
/>
</cfif>	
}

Open in new window

It  is triggered by onclick when a user wants to see the details of a item returned in the search
No - I can't form post back
Using the go(-1) sux especially in this case.
Hmm, that's really not server-side validation, unless I am not reading it correctly.

It's appears to be a javascript function that has embedded Coldfusion in it.   Once the server-side process has completed, you are left with just a js function that opens a window.   If killsurvey ends up to be 1 then the function will do nothing.

It may help, you can throw out the coldfusion check for the cookie and use a javascript check for the cookie instead.  Basically, the function is saying if cookie does not exist set a cookie and open the window.  If the cookie doesn't exist, do nothing.   That can be done in javascript if you want.
Avatar of ecpeel

ASKER

you mean convert the the entire function to javascript so all validation takes place on the client?
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ecpeel

ASKER

Looks reasonable.
But won't the same issue exist (persist) because of using history.go as a back button instead of re-running the search?
By using history.go (the real culprit), the CF code will never check for the existence of the cookie even if the script is in the onclick event?
Avatar of ecpeel

ASKER

Ok, here's what I ended up doing that worked. Inspired by you and including your code mixed with another's found http://stackoverflow.com/questions/5968196/check-cookie-if-cookie-exists and what I relearned is that CF even tucked inside of a javascript function only runs when the page loads. Thanks as always gdmaria

	<script>
			  
		function getCookie(name) { 
		    var dc = document.cookie; 
		    var prefix = name + "="; 
		    var begin = dc.indexOf("; " + prefix); 
		    if (begin == -1) { 
		        begin = dc.indexOf(prefix); 
		        if (begin != 0) return null; 
		    } 
		    else 
		    { 
		        begin += 2; 
		        var end = document.cookie.indexOf(";", begin); 
		        if (end == -1) { 
		        end = dc.length; 
		        } 
		    } 
		    return unescape(dc.substring(begin + prefix.length, end)); 
		}  
		
	
		function showSearchSurvey(){
				
			    var myCookie = getCookie("searchResultsSurvey.clickedSurvey"); 
			 
			    if (myCookie == null) { 
			        // do cookie doesn't exist stuff; 
			        window.open('https://www.surveymonkey.com/jsPopInvite.aspx?sm=03kYcE5oyzMT7O5A7k0E8w%3d%3d', 'invitationwindow', 
								'height=350,width=500,scrollbars=yes,resizable=yes,status=yes');		
						
					SetCookie('searchResultsSurvey.clickedSurvey','Yes');		
					
			    } 
			    else { 
			        // do cookie exists stuff or nothing at all
			        //alert('yeah its found');
			    } 
			}

		function SetCookie(cookieName,cookieValue,nDays) {
			  var today = new Date();
			  var expire = new Date();
			  if (nDays==null || nDays==0) nDays=1;
			  expire.setTime(today.getTime() + 3600000*24*nDays);
			  document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
			  }
	</script>

Open in new window

Avatar of ecpeel

ASKER

Thanks gdmaria