Solved

CFLocation and javascript

Posted on 2004-10-15
13
1,104 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
 
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now