Javascript & Mail Clients

Gnomo

Registered
I have a puzzle of a javascript that I could use help with.

I am trying to come up with a method for putting email addresses into a website in such a way that they cannot be harvested by spambots (The javascript methods of "encoding" the email address are not secure enough IMHO), however my bosses are mandating that if someone click on the email link that it open their email client, so I can't use a email form. I also want to incorporate the companies LDAP server into the scenario so that if someone changes their email address, I don't have to recode pages.

So, here is what I would like to do:

The user click on a link on the web page. A pop-under window appears that calls a PHP page that queries the LDAP server and returns a http-location header that opens the email client. The pop-under window should then automatically disappear.

So far I have the PHP script working and it returns the header I need and the email client does open. Also I can create a pop-under window that will automatically disappear (since a http-location header is being returned, I can't put any javascript after it to close the window).

The problem that I am having is that whenever I try to combine the two (have the pop-under window link to the php page) either the window does not close, or the php page does not "load" until the javascript has completed executing (in which case the window is closed before the needed header is returned). I have tried various methods to delay the execution of the window.close command, however it always seems that this either causes the command to not execute (as is the case with setTimeout() ) or the page does load until after the javascript completes (as is the case with do nothing loops)

Here is what my javascript looks like:
<a href="" onClick="popUnder = window.open('test.php?name=foo');popUnder.blur();popUnder.close();">Email me</a>

Any Help or Ideas of other ways to open a email client from a web browser would be appreciated.
 
You could use a meta command to automatically refresh the page to a new URL after so many seconds, and it would point to a URL that automatically closes the page. This uses HTML only (for the first part at least) and will allow your PHP page to "load" correctly.
 
I had thought of that, however the problem is that the PHP page that loads in the pop-under uses
PHP:
header("location: $email");
to open the mail client. Since this is a redirect to an email address, their is no html output to the browser.

I got the javascript working in Mozilla based browsers. However, I need to get it to work in Safari and IE (for mac & windoze) otherwise my boss won't accept it.

Here is what the code currently looks like:

var popunder;
var first = true;
var t;
function closeWindow()
{

popunder.close()
}
function sleep()
{

if( self.first )
{

self.first = false;
t = setTimeout("sleep()", 100);
}
else
{

clearTimeout( t );
self.first = true;
closeWindow();
}
}
function openPopUnder()
{

popunder = window.open('test.php?name=foo');
popunder.blur();
sleep();
}
 
Okay,

So I've decided to scrap the popUnder idea. I could only get it to work in Mozilla, and I have no idea why it was not working for other browsers.

My New Idea is to, using javascript, create and iframe that will load the page I need and the just remove the element after a short period of time has elapsed.

I did some research on Apple's Site and I think I understand what I need to do. However, I have been experiencing problems.

Thus far I have only copied the snippets of example code off of apple's website. When I view the pages (from apple's site) the examples they have work fine. However, when i try to load the examples from localhost they do not work. Safari does not show any changes to the page, mozilla will show the change for about 1/30 of a second (long enough to see that it changed) before the added elements (table cells) disappear and the page looks like it did before I click the button.

Any ideas what I might be doing wrong?
 
Okay, so I must have been really tired last night, because when I woke up this morning and started over (from scratch) I got Apple's examples to work.

So, currently my javascript creates a iframe element and loads the php page into the iframe.

In mozilla: the php page redirects the iframe to an email address and opens the email client. If I start the javascript again, it will reload the iframe (using location.replace ) and it keeps on working. :)

In Safari: the php page redirects the iframe and opens the email client. However, the redirect causes an error "frame load interrupted". :confused:

In IE (for both Mac and Windoze): The iframe is created, but after that nothing happens. I cannot tell if the php page has been loaded or not. The email client does not open. If I restart the script, nothing happens. ::evil::

If anyone has the time to help me out on this, let me know and I'll attach the .js file.
 
Back
Top