Solved

CFLocation and javascript

Posted on 2004-10-15
13
1,138 Views
Last Modified: 2013-12-24
Can you set the url paramter of the cflocation tag to be a javascript command?  I am not having any luck.

What I have done is created a page that queries for emails, then set the url in cflocation to equal "mailto:#queryoutput#".  It works great but leaves a blank IE window open every time the link is clicked which is s pain:

<cfif not isdefined("URL.group")>
      <p>Sorry, no groups were selected.</p>
      <cfabort>
<cfelse>
      <cfquery name="get_data" datasource="email_groups">
      SELECT * FROM main_data
      WHERE #URL.group# = 1
      </cfquery>

      <cfset catch_var = "">
      <cfloop query="get_data">
            <cfset catch_var = Insert(#get_data.email_add#, #catch_var#, 0)>
            <cfset catch_var = Insert(";", #catch_var#, 0)>
      </cfloop>
      <cfset catch_var = RemoveChars(#catch_var#, 1, 1)>
      <cfset catch_var = Insert("mailto:", #catch_var#, 0)>
      <cflocation url="#catch_var#">
      <cflocation url="javascript:window.close()">
</cfif>
0
Comment
Question by:skibama1
13 Comments
 
LVL 7

Expert Comment

by:black0ps
ID: 12318699
You can't have two cflocations right after each other. Doesn't work.

If you want the window to close, try something like:

<cflocation url="close.cfm">

close.cfm:
<body onLoad="javascript:window.close();">
</body>

However, what are you trying to do with the code. I'm not sure the <cflocation url="mailto:some@email.com"> is going to accomplish what you want it to do.
0
 
LVL 1

Author Comment

by:skibama1
ID: 12320149
I know the mail part works but when the link is called it leaves an open IE window with nothing in it.  My users are complaining that they love being able to click on the groups and send email but they HATE the windows that are left open.
0
 
LVL 5

Expert Comment

by:smaglio81
ID: 12320172
BlackOps is right. And he has a good question: what is it that you want to do?

I have 2 guesses but both dont really seem right.
1) Maybe you want to setup a link to send the emails in which case you would want to use <a href="#cathc_var#">Email Group</a>.
2) Maybe you want to send an email yourself, in which case you might want to use <cfmail>.

Also, the javascript command for url changing is 'document.location="<come URL>"'.

HTH

Steven
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 35

Expert Comment

by:mrichmon
ID: 12320633
Black0ps is right and so is everyone else that is going to tell you you can't do that.

The reason the window is left open is 2 fold.

1) You should not have javascript inside the cflocation

2) When the 1st cflocation is executed the window the second one won't be.

Personally I would not do what you are doing anyway because the mailto  is limited.

Why not have a form that sends the email and then sends them back to where they want to go?


But if the mail part is doing what you want for now then I recommend that you instead of doing a cflocation to a mail do a cflocation to a page that has the email link and onclick of the link it closes the window.
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12321488
What I suggest is instead of doing the processing on the next page with the link, do the processing on the page that has the links the user's can click on.

    <cfquery name="get_data" datasource="email_groups">
     SELECT * FROM main_data
     WHERE #URL.group# = 1
     </cfquery>

     <cfset catch_var = "">
     <cfloop query="get_data">
          <cfset catch_var = Insert(#get_data.email_add#, #catch_var#, 0)>
          <cfset catch_var = Insert(";", #catch_var#, 0)>
     </cfloop>
     <cfset catch_var = RemoveChars(#catch_var#, 1, 1)>
     <cfset catch_var = Insert("mailto:", #catch_var#, 0)>

<!--- Output link --->
<cfoutput><a href="#catch_var#">Group Number 1</a></cfoutput>    

*break*
To: smaglio81 & mrichmon:
Thanks for the validation. Sometimes I wonder if i'm not talking out of my butt.
0
 
LVL 1

Author Comment

by:skibama1
ID: 12322454
OK, I see what everyone is saying.  But let me explain what I am doing and then you may be able to help me more.  I work at a school with a VERY lazy IT group.  Email groups on the exchange server is very low on their priority list....so low that I'm not even sure it makes the list.  Just as with most other organizations we have lots of people (150+ staff members) and Lots of groups - probably on the order of 75 groups.  Well the IT won't give me access to go in and create the groups on my own....go figure.

So to get around it I created a database with all of our employees matched up with all the possible email groups.  I have a page that has all the groups as a link.  The "email group" links on this page (regular http links) calls another page (code above) with a URL variable telling the query which group to find.  It then builds a mailto link and calls that from the cflocation.

So far I am leaning towards blackOps last suggestion, but I don't like the fact that the "menu" window would not stay open.  Alot of users have the page set up directly in Outlook (as a folder homepage) and I suspect this would cause problems.  What I would really like to see is when the user clicks on the menu page the only thing that remains open is the new email. If this is called through another window I would like for that window to close on it's own. Since the window would be a child it shouldn't be too hard to close it with some sort of javascript.
0
 
LVL 1

Author Comment

by:skibama1
ID: 12322482
I forgot to say that cfmail is out of the question because of firewall reasons.  It actually would have been my choice but with the firewall it was kaput.
0
 
LVL 7

Accepted Solution

by:
black0ps earned 125 total points
ID: 12322980
Try the following:

Page 1 with links:
List all of your groups like you have it now.

Page 2 with processing from above:
  Instead of putting the mailto link with cflocation use:
<script language="Javascript">
<!--
window.open('#catch_var#');
window.close();
//-->
</script>
You may get a security prompt asking you if you want to close the window. If I find a way around that, i'll post it here.
0
 
LVL 1

Author Comment

by:skibama1
ID: 12323221
That might work.  I'll try it this weekend sometime.  Wish i could get past that firewall....
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12323573
To get past the firewall, have you tried using the same outgoing mail in the cfmail tag as the exchange server uses? I mean, mail has to get out somehow doesn't it?
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12323595
Just leave out the window.close() in the javascript if you don't want the main window to open. When you use window.open('mailto:whoever'); it opens up an email page and not a new window.
0
 
LVL 1

Author Comment

by:skibama1
ID: 12326262
I tried using doing that do get past the firewall but because they won't let the server be part of the domain I could not get a connection.  They are incredible paranoid.
0
 
LVL 1

Author Comment

by:skibama1
ID: 12356575
Worked like a charm!  Thanks!
0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question