Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help defining a frame in a send to friend script...

Status
Not open for further replies.

KDiesel

Technical User
Jul 27, 2003
7
US

u = window.location;
m = "The message";
function mailThisUrl(){
good = false
checkEmailAddress(document.eMailer.address)
if (good){
// the following expression must be all on one line...
window.location = "mailto:"+document.eMailer.address.value+"?subject="+m+"&body="+document.title+" "+u;
}
}
</script>

So heres my problem. I can get the e-mail to open up, with a button, and have the URL in the body, but its the incorrect URL. How can I tell the script to look at a certain frame? When I try things like window.location.mainFrame it says &quot;Undefined&quot;. Also, even when I can get a link up, it truncates it, it will not show anything past a & sign.
 
Without more code, I'm guessing here, but something along the lines of:

Code:
u = parent.FRAME_NAME.location.href;

...might work.

Good luck.

--Dave
 
no luck, with

parent.mainFrame.location.href

any other ideas?
 
>> any other ideas?

As LookingForInfo said... Without more code, we're guessing.

So... My next idea would be for you to post the rest of your code.
 
Give us some more code and an idea of your frame layout, etc. Can you give a pared down example of what you are talking about?

--Dave
 
Here is all the code:

The Script in the Header:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin

//Tell-a-friend script
//Carl Dimmer

var initialsubj=&quot;ddd&quot;
var initialmsg=&quot; &quot;+window.parent.location
var good;
function checkEmailAddress(field) {

var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
if (goodEmail) {
good = true;
}
else {
alert('Please enter a valid address.');
field.focus();
field.select();
good = false;
}
}
u = window.location;
function mailThisUrl() {
good = false
checkEmailAddress(document.eMailer.email);
if (good) {

//window.location = &quot;mailto:&quot;+document.eMailer.email.value+&quot;?subject=&quot;+initialsubj+&quot;&body=&quot;+document.title+&quot; &quot;+u;
window.location = &quot;mailto:&quot;+document.eMailer.email.value+&quot;?subject=&quot;+initialsubj+&quot;&body=&quot;+initialmsg
}
}
// End -->
</script>

The Form in the Body:

<form name=&quot;eMailer&quot;>
<div align=&quot;center&quot;><font size=&quot;2&quot; face=&quot;Georgia, Times New Roman, Times, serif&quot;>Send
this page to a friend:
<input type=&quot;text&quot; name=&quot;email&quot; size=&quot;26&quot; value=&quot; Enter Address Here&quot; onFocus=&quot;this.value=''&quot; onMouseOver=&quot;window.status='Enter email address here and tell a friend about this site...'; return true&quot; onMouseOut=&quot;window.status='';return true&quot;>
<input name=&quot;button&quot; type=&quot;button&quot; onClick=&quot;mailThisUrl();&quot; onMouseOver=&quot;window.status='Click to send an email (with this page address) to a friend! Enter email address above...'; return true&quot; onMouseOut=&quot;window.status='';return true&quot; value=&quot;Send&quot;>
</font><br>
</div>
</form>

You can view what I am trying to do by going to and going to the store, look at an item in detail, then click on print, you will then understand how it looks.
 
Okie-dokie... the problem is not so much that you are doing anything wrong. What happens is the URL of the page that you are sending contains a whole heap of ampersands - deliniating paramaters which determine which page the database dishes up.

Problem: The mailto link interprets these ampesands as being instructions for it to follow.

Solution: use escape() to transform the URL into a portable string. So where you currently have:
Code:
window.location = &quot;mailto:&quot;+document.eMailer.address.value+&quot;?subject=&quot;+m+&quot;&body= &quot;+u;
Use:
Code:
window.location = &quot;mailto:&quot;+document.eMailer.address.value+&quot;?subject=&quot;+m+&quot;&body= &quot;+escape(u);

And you should have no problems with truncated URLs.

One other thing - Where you define the value of 'u':
Code:
u = parent.mainFrame.location.href;
parent.mainFrame is redundant. This is mainFrame. Kind of like me referring to myself as &quot;my father's eldest son&quot;. Use:
Code:
u = location.href;
and you will avoid the problem of then, when the email recipient loads the page outside of the frameset, having a [tt]parent.mainFrame.location is null or not an object[/tt] error.
 
I get an error using:

window.location = &quot;mailto:&quot;+document.eMailer.address.value+&quot;?subject=&quot;+m+&quot;&body= &quot;+escape(u);
 
>> now is there anyway I can make that link be hidden with other text

No... all you will succeed in doing would be to put the raw html code into the email body. If you could prepopulate HTML (And therefore VBScript) into the user's email client it would be a pretty nasty security hole. Also it would assume that every email client is HTML capable.
 
Ok, Thanks for the answer, how can I make a page break, so I can type something before the link, so it would look like this

Subject:Dawn Hill Antiques
Body:


LINK

So there is a space above the link where people can write a message?
 
Code:
escape('\n\n\n' + u)

\n is the JavaScript newline character so this code will insert three blank lines before the link. You could also add some text in there like:
Code:
escape('\n\n\nFollow this link to the referring page:' + u)

But be mindful that the maximum length for the mailto statement URL (address, subject, cc, bcc and body) is 256 characters.
 
This is not working on a Mac thats running OS x and is using entourage as its default client. It cuts off at the ampersands and deliminating marks. Any code for this? Browser is IE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top