nyteschayde
03-11-2004, 10:04 PM
Okay here's the deal. I am working on this favelet (a snippet of JavaScript that can be pasted into the url line or setup as a clickable favorite to modify code on the page) that searches through all the links in all the frames and adds an onclick event to those whose href's begin with mailto:.
The onclick event opens a new window and allows you to compose the message using your Yahoo email rather than an externally configured mail application.
This works on all major browsers. It even works on Netscape 4 for gods sake and it won't work in IE. The only way it works in IE is if its part of a script tag that's actually embedded in the page to begin with. This makes the point of this script moot.
Things I've tried are: Converting the code to an escaped string and basically doing javascript:eval(unescape('...')). But that doesn't work either.
Here is the code as it would appear on in the favorite or url line:
There should be no space between java and script:, but the post keeps inserting a space there. Please remove to test.
javascript:{for(var f = 0, fct = frames.length; ((fct > 0) ? (f<fct) : (f<1)); f++){var doc=(fct>0)?frames[f].document:document,cnt=doc.links.length,lnk=doc.links;for(var i = 0; i < lnk.length; i++){if(lnk[i].href.indexOf("mailto:")!=-1){var qstr=lnk[i].href.toString().toLowerCase().split("?"),pairs=null,pair=null,j=0;lnk[i].to=qstr[0].split(":")[1];lnk[i].subj="";if(qstr.length){qstr=qstr[1]||"";pairs=qstr.split("&");for(j=0;j<pairs.length;j++){pair = pairs[j].split("=");if((pair[0]||"")=="subject")lnk[i].subj=pair[1]||"";}}lnk[i].onclick=function(){this.wind = window.open("http://us.f804.mail.yahoo.com/ym/Compose?login=1&to="+unescape(this.to)+"&subject="+unescape(this.subj),"Compose");return false;}}}}alert("All mailto: links have been modified");}
and here it is again formatted for easy viewing:
for(var f = 0, fct = frames.length; ((fct > 0) ? (f<fct) : (f<1)); f++)
{
var doc=(fct>0)?frames[f].document:document,cnt=doc.links.length,lnk=doc.links;
for(var i = 0; i < lnk.length; i++)
{
if(lnk[i].href.indexOf("mailto:")!=-1)
{
var qstr=lnk[i].href.toString().toLowerCase().split("?"),pairs=null,pair=null,j=0;
lnk[i].to=qstr[0].split(":")[1];
lnk[i].subj="";
if(qstr.length)
{
qstr=qstr[1]||"";
pairs=qstr.split("&");
for(j=0;j<pairs.length;j++)
{
pair = pairs[j].split("=");
if((pair[0]||"")=="subject")
lnk[i].subj=pair[1]||"";
}
}
lnk[i].onclick=function()
{
this.wind = window.open("http://us.f804.mail.yahoo.com/ym/Compose?login=1&to="+unescape(this.to)+"&subject="+unescape(this.subj),"Compose");
return false;
}
}
}
}
alert("All mailto: links have been modified");
It seems to be breaking on the URL (as best as I can tell) at the for(j=0...) line. There is nothing wrong with the JavaScript as far as I can tell.
For those of you who don't know the syntax var x = val || defaultVal; basically assigns val to x if val is a valid value and if not, undefined or null for example, defaultVal is assigned to x. This is part of the JavaScript reference language and is quite useful. I am explaining it because it is somewhat rare and not everybody knows about it.
Please let me know as I am stumped on this.
-nyteschayde
The onclick event opens a new window and allows you to compose the message using your Yahoo email rather than an externally configured mail application.
This works on all major browsers. It even works on Netscape 4 for gods sake and it won't work in IE. The only way it works in IE is if its part of a script tag that's actually embedded in the page to begin with. This makes the point of this script moot.
Things I've tried are: Converting the code to an escaped string and basically doing javascript:eval(unescape('...')). But that doesn't work either.
Here is the code as it would appear on in the favorite or url line:
There should be no space between java and script:, but the post keeps inserting a space there. Please remove to test.
javascript:{for(var f = 0, fct = frames.length; ((fct > 0) ? (f<fct) : (f<1)); f++){var doc=(fct>0)?frames[f].document:document,cnt=doc.links.length,lnk=doc.links;for(var i = 0; i < lnk.length; i++){if(lnk[i].href.indexOf("mailto:")!=-1){var qstr=lnk[i].href.toString().toLowerCase().split("?"),pairs=null,pair=null,j=0;lnk[i].to=qstr[0].split(":")[1];lnk[i].subj="";if(qstr.length){qstr=qstr[1]||"";pairs=qstr.split("&");for(j=0;j<pairs.length;j++){pair = pairs[j].split("=");if((pair[0]||"")=="subject")lnk[i].subj=pair[1]||"";}}lnk[i].onclick=function(){this.wind = window.open("http://us.f804.mail.yahoo.com/ym/Compose?login=1&to="+unescape(this.to)+"&subject="+unescape(this.subj),"Compose");return false;}}}}alert("All mailto: links have been modified");}
and here it is again formatted for easy viewing:
for(var f = 0, fct = frames.length; ((fct > 0) ? (f<fct) : (f<1)); f++)
{
var doc=(fct>0)?frames[f].document:document,cnt=doc.links.length,lnk=doc.links;
for(var i = 0; i < lnk.length; i++)
{
if(lnk[i].href.indexOf("mailto:")!=-1)
{
var qstr=lnk[i].href.toString().toLowerCase().split("?"),pairs=null,pair=null,j=0;
lnk[i].to=qstr[0].split(":")[1];
lnk[i].subj="";
if(qstr.length)
{
qstr=qstr[1]||"";
pairs=qstr.split("&");
for(j=0;j<pairs.length;j++)
{
pair = pairs[j].split("=");
if((pair[0]||"")=="subject")
lnk[i].subj=pair[1]||"";
}
}
lnk[i].onclick=function()
{
this.wind = window.open("http://us.f804.mail.yahoo.com/ym/Compose?login=1&to="+unescape(this.to)+"&subject="+unescape(this.subj),"Compose");
return false;
}
}
}
}
alert("All mailto: links have been modified");
It seems to be breaking on the URL (as best as I can tell) at the for(j=0...) line. There is nothing wrong with the JavaScript as far as I can tell.
For those of you who don't know the syntax var x = val || defaultVal; basically assigns val to x if val is a valid value and if not, undefined or null for example, defaultVal is assigned to x. This is part of the JavaScript reference language and is quite useful. I am explaining it because it is somewhat rare and not everybody knows about it.
Please let me know as I am stumped on this.
-nyteschayde