Solved

CFLocation and javascript

Posted on 2004-10-15
13
1,146 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
[X]
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
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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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