/    Sign up×
Community /Pin to ProfileBookmark

How do i retrieve the href value without FQDN being appended

All,
Have a quick question.

I have a link as such:

[code=html]<a href=”#”>Some Link</a>[/code]

I bind an onclick event to it which is:

[code=html]alert(this.href);[/code]

What I get back is something like “http://localhost/file.php#”.

What I want to see is just the hash mark (To decide whether it is an anchor/js caller/etc or a real valid link). Is there another property that does not append the FQDN to the href value?

Thanks!

–james

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@_Aerospace_Eng_Nov 03.2006 — What is it that you are trying to do? What would it matter of whether or not its an anchor, js call, or valid link?
Copy linkTweet thisAlerts:
@semi-sentientNov 03.2006 — &lt;html&gt;
&lt;head&gt;
&lt;title&gt;Test Link&lt;/title&gt;
&lt;script language="javascript" type="text/javascript"&gt;
function checkLink(url) {
if (url.indexOf("#") != -1) {
alert("it's an anchor");
} else if (url.indexOf("javascript:") != -1) {
alert("it's a call to a javascript function");
} else {
alert("it's a normal URL");
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;a href="#" onclick="checkLink(this.href);"&gt;anchor&lt;/a&gt;&lt;br /&gt;
&lt;a href="javascript:void(0);" onclick="checkLink(this.href);"&gt;js call&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.google.com/" onclick="checkLink(this.href);"&gt;normal link&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @jholder 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 5.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...