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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript generating links

Status
Not open for further replies.

cajchris

Programmer
Oct 13, 2005
57
GB
hi,

i am wanting my javascript function to generate a mailto link on a page and have the following code:

oParser.CreateEMailUri = function(address)
{
var sBaseUri = 'mailto:' + address ;

var sParams = '' ;

sParams = ' class=' + escape( "EmailLink" ) ;

return sBaseUri + sParams ;
}

this returns:

<a href="mailto:vcvcvcxvxcvcxv class=EmailLink">

however I want to have the parameter appear as class="EmailLink" so that the entire line reads:

<a href="mailto:vcvcvcxvxcvcxv" class="EmailLink">

any ideas

regards
cajchris
 
Sure - change the line in your function to read:
Code:
sParams = ' class="' + escape( "EmailLink" ) + '"';
Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
i tried that babyjeffy and now i get:

<a href="mailto:ccxscxfdzdfdf class=&quot;EmailLink&quot;">

any further ideas,

thanks for the quick response tho :)

 
Or to:
sParams = ' class=' + "\"EmailLink\"";

Is there a need to keep the escape call in there?

Paranoid? ME?? WHO WANTS TO KNOW????
 
unbfortunately that still returns:

<a href="mailto:cdxccxcxcccv class=&quot;EmailLink&quot;">

in my html page.

remembering that my function is now

oParser.CreateEMailUri = function(address)
{
var sBaseUri = 'mailto:' + address ;

var sParams = '' ;

sParams = ' class=' + "\"EmailLink\"";

return sBaseUri + sParams ;
}
 
Another change:
var sBaseUri = 'mailto:"' + address + '"';

I do not know how you insert this into your HTML and that

Paranoid? ME?? WHO WANTS TO KNOW????
 
You are obviously not giving us all the code that is play here... since it appears you are somehow escaping the returned result as well (somewhere) - otherwise you would not get &quot; in place of " in your code.

The following test harness works exactly as expected. You need to look at the rest of your code for this new problem you have noticed.
Code:
<html>
<head>
<script type="text/javascript">
function test(address) {
    var sBaseUri = 'mailto:' + address ;
    var sParams = '' ;
    sParams = ' class="' + escape( "EmailLink" ) + '"';
    return sBaseUri + sParams ;
}
</script>
</head>
<body>
<a href="javascript:alert(test('something'));">Test</a>
</body>
</html>

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
in the same .js file there is a function which is called when the ok button in the dialog is clicked. as the person building the site can highlight text, and add a link to it which in this case is mailto and enter the address.

case 'email' :
sUri = GetE('txtEMailAddress').value ;

if ( sUri.length == 0 )
{
alert( FCKLang.DlnLnkMsgNoEMail ) ;
return false ;
}

sUri = oParser.CreateEMailUri(sUri) ;
break ;

so the sUri passed to the previous discussed function is say "anaddress". then we get back the entire mailto link. but is somehow placing &quot; in for a "
 
so the sUri passed to the previous discussed function is say "anaddress". then we get back the entire mailto link. but is somehow placing &quot; in for a "
Exactly. Hehe... I see by your variables... you're using that FCKEditor - nice stuff.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
thats right i am. its within a package called infoglue. is this a problem then?

is there no way to get around this?

regards,
cajchris
 
You are not closing your quote after the address which is causing one of your problems as you run into quote collisions.

Change:
var sBaseUri = 'mailto:' + address ;
To:
var sBaseUri = 'mailto:' + address + '"';

If you still get the &quot around EmailLink but you did not get it prior to taking out the escape then modify your line like this:
sParams = ' class=' + '"' + escape( "EmailLink" ) + '"';

Your final string should look like:
mailto:vcvcvcxvxcvcxv" class="EmailLink"

You did not include an opening quote before mailto so you will have to append
<a href=" to the beginning and >linktext</a> to the end however you are doing it in your code.



Paranoid? ME?? WHO WANTS TO KNOW????
 
when i hover over the link on the page it appears at the bottom of the window as:

mailto:vcvcvcxvxcvcxv" class="EmailLink"

but in the source for the page it is still:

<a href="mailto:vfvcvccvcvcvcv&quot; class=&quot;EmailLink&quot;">

this is becoming really frustrsing as i cannot see why it would be doing this!!! :-(

regards
cajchris
 
How does the link get written to the page?
The link should not appear as you show it, it should only show as mailto:vcvcvcxvxcvcxv
If it is showing more then you have a nested quote problem.

How do you handle the string that gets returned? How does it get placed on the page?


Paranoid? ME?? WHO WANTS TO KNOW????
 
the link gets written to the page as i have said. i have not done any manipulation on the string that i am aware of. after this string is obtained it seems to generate the link. the only area i can see anything getting written out is from the code i have already uploaded.
 
Thats just it, you have not shown us how it gets to the page. You just said you have a function that when they highlight text and click a button it adds a link to the highligted text. But HOW that happens is not show. You show the code for generating PART of the string for the link and you return it to the value sUri. What happens after that point is a mystery.

First of all, the string you return is:
mailto:mailto:vfvcvccvcvcvcv" class="EmailLink"

It NEEDS to be:
<a href="mailto:vfvcvccvcvcvcv" class="EmailLink">vfvcvccvcvcvcv</a>

So you get back an incomplete string stored under the variable sUri and that has to somehow be written to the page but how that happens is still a mystery to us.
So something else is still going on in your code after that point in order to put in the <a href=" the > and the </a> pieces. And I suspect that in that code somewhere it is converting your embeded quotes to &quot before writing it to the screen. You either need to stop it from converting or you have to convert the &quot's back again before it writes it to the page.



Paranoid? ME?? WHO WANTS TO KNOW????
 
i dont even know how the a href parts are added on either. this is from the fckeditor i am using. the code is part of a package i am using called infoglue. and i have searched for days trying to determine where these tags are added. but i cannot find them. :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top