Reply
Issues with javascript in href of <a> tag
Old 03-30-2008, 08:12 PM Issues with javascript in href of <a> tag
Junior Talker

Posts: 3
Name: 2gig
ok so i have the code:

Quote:
link(url);
{
var http="http://";
var start='index.html?fsrc="'
if (url.indexOf("www.")==0)
{
var furl=http.concat(url);
}
else
{
furl=url;
}
var ffurl=start.concat(furl);
return ffurl;
}
It's supposed to be used something like this:
Quote:
<a href='link("www.google.com")'>Text</a>
The issue I keep having is that it does nothing. I've got no clue what I'm doing wrong.

The first thing its supposed to do is check if the first 4 characters of the url inserted in link() are "www.". If they are, it's supposed to put an "http://" in front of it. Then its supposed to combine it with 'index.html?fsrc="' to make something like: index.html?fsrc="http://www.google.com". Then its supposed to use that as the href for the link.

I'm not new to javascript, but I don't write my own functions too often, and i rarely ever manipulate strings like this. Also, I've never used a function in an "a" tag before.

Thanks in advance.
outermon is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 03-30-2008, 08:48 PM Re: Issues with javascript in href of <a> tag
tripy's Avatar
Fetchez la vache!

Posts: 2,054
Name: Thierry
Location: In the void
Code:
...
return ffurl;
not a surprise it does nothing, as it should be used by something else and be using the return to do something.

maybe something like
Code:
<a href='top.location=link("www.google.com");'>Text</a>
but this is plain dumb...
Search engines cannot follow a link like that.
Browsers with javascript disabled cannot follow them neither.

And furthermore, what for !?
Why follow a link whose URI have been generated via javascript?
I cannot see any good reason for it.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-01-2008, 11:27 AM Re: Issues with javascript in href of <a> tag
willcode4beer's Avatar
Webmaster Talker

Posts: 695
Name: Paul Davis
Location: San Francisco
Though best practices recommend against it, what you want to do is:

Code:
<a href="javascript:link('www.google.com')">Text</a>
__________________
Paul Davis
willCode4Beer.com (coding for all the right reasons)
willcode4beer is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Issues with javascript in href of <a> tag
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11287 seconds with 12 queries