Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

CFLocation and javascript

Posted on 2004-10-15
13
1,129 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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