/    Sign up×
Community /Pin to ProfileBookmark

help with javascript question

hello,

I cannot find out how to insert a link in html (php) when javascript is enabled and if javascript is not enabled, no link.

I have a link “email” who’s calling a javascript to create the email address.
If users do not have javascript enabled the link gives an error.
The no script tag is not a solution because the link “email” will be displayed always with this tag.

Wibo

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@_Aerospace_Eng_Nov 23.2006 — [code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function createEmail()
{
// Sets up email parts
var email1 = 'you';
var email2 = '@';
var email3 = 'domain.com';

// Combines the parts
var emailwhole = email1 + email2 + email3;

// Creates a link
var emaillink = document.createElement('a');

// Sets link text
var emailtext = document.createTextNode(emailwhole);
emaillink.appendChild(emailtext);

// Sets link href
emaillink.setAttribute('href','mailto:'+emailwhole);

// Puts link in span with id="emailhold"
document.getElementById('emailhold').appendChild(emaillink);
}
window.onload = createEmail;
</script>
</head>
<body>
<span id="emailhold"></span>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@wiboauthorNov 23.2006 — Can you please tell me how would it be with my email script:

<script language="JavaScript"><!--
function Post(name, company, domain) {
locationstring = 'm' + 'ai' + 'lto:' + name+ '@' + company+ '.' + domain;
window.location.replace(locationstring); }
//--></script>


<span class="smalltext"><a href="javascript:Post('myname','mycompany','mydomain')">email</a>&nbsp;</span>
Copy linkTweet thisAlerts:
@wiboauthorNov 23.2006 — [code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function createEmail()
{
// Sets up email parts
var email1 = 'you';
var email2 = '@';
var email3 = 'domain.com';

// Combines the parts
var emailwhole = email1 + email2 + email3;

// Creates a link
var emaillink = document.createElement('a');

// Sets link text
var emailtext = document.createTextNode(emailwhole);
emaillink.appendChild(emailtext);

// Sets link href
emaillink.setAttribute('href','mailto:'+emailwhole);

// Puts link in span with id="emailhold"
document.getElementById('emailhold').appendChild(emaillink);
}
window.onload = createEmail;
</script>
</head>
<body>
<span id="emailhold"></span>
</body>
</html>[/code]
[/QUOTE]


Something is wrong with the script.

I receive a Template Parse Error.

What can it be?
Copy linkTweet thisAlerts:
@_Aerospace_Eng_Nov 23.2006 — Nothing is wrong with the script. Something is wrong with the way your software parses the code.
Copy linkTweet thisAlerts:
@wiboauthorNov 23.2006 — Nothing is wrong with the script. Something is wrong with the way your software parses the code.[/QUOTE]

my page is a PHP page.

Can this be the reason?
Copy linkTweet thisAlerts:
@_Aerospace_Eng_Nov 23.2006 — Post your code including the php.
Copy linkTweet thisAlerts:
@wiboauthorNov 23.2006 — I've sent you a PM.
Copy linkTweet thisAlerts:
@_Aerospace_Eng_Nov 23.2006 — Umm yeah how can I see php if its already parsed? Think about it. How do you enter new code? Try this
&lt;script type="text/javascript"&gt;
function createEmail()
{
var email1 = 'you';
var email2 = '@';
var email3 = 'domain.com';
var emailwhole = email1 + email2 + email3;
var emaillink = document.createElement('a');
var emailtext = document.createTextNode(emailwhole);
emaillink.appendChild(emailtext);
emaillink.setAttribute('href','mailto:'+emailwhole);
document.getElementById('emailhold').appendChild(emaillink);
}
window.onload = createEmail;
&lt;/script&gt;

Then put this where you want the email link to be.
&lt;span id="emailhold"&gt;&lt;/span&gt;
I'm going to guess that you probably don't even know php.
Copy linkTweet thisAlerts:
@wiboauthorNov 23.2006 — Yeesssss..... your new version seems to work. ?

Please can I ask you some more questions?

1)

If javascript is enabled there's a real email link inside (see url).

I would like to have a <a href=mailto:"emailaddress">email </a>

link is this possible?

It would even be better if user cannot see my email address in the status bar

with mouseover button but as I had before javascript:"myname/domain/extension"

2)

Do you know what to do if I want to write something on the page if javascript is not enabled?

p.e. "please enable javascript"

would it be possible to show the link also to the user if he doesn't have javascript enabled and when he clicks on it give him a pop-up message

"please enable javascript"

3)

the email link is shown very slow.

Is it possibile to load the email address faster?

Thank you very much again for your great help
Copy linkTweet thisAlerts:
@_Aerospace_Eng_Nov 23.2006 — 1) Thats what the script does

2) You can use
&lt;noscript&gt;Please enable javascript&lt;/noscript&gt;
The script I wrote will only create the email link if JS is enabled. It will show nothing if JS is not enabled.

3) Not sure what you mean by this, do you mean when it loads up in outlook or something? If so then no nothing you can do about that.
Copy linkTweet thisAlerts:
@wiboauthorNov 23.2006 — Dear _Aerospace_Eng_

I think I have found the solution of the script I have actually on my site.

It will resolve all my questions.

Do you know how to write the URL below within document.write?:

<a href="javascript?ost('myuser','mydomain','myextension')">email</a>

Wibo
×

Success!

Help @wibo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...