Hi everybody, I'm a total beginner using Javascript and I would like to know how can I get in a variable the url of hyperlinks? I want to do something like a status bar of mozilla (not a bar) but just get the urls no matter the extension of the hyperlinks (.html, .php, .pdf, etc). So please I need your help :) . Thanks
Sep 13 '07
15 2829 gits 5,390
Recognized Expert Moderator Expert
hi ...
when clicking something you may retrieve the event target, lets assume that you click a hyperlink the:
or:
is 'A'.
kind regards
Finally I resolve my problem!!!, I just needed to read the <a href> tags of the HTML document in the web navigator!! thanks everyone for helping me and I hoppe we'll see you again in this forum.!!!
gits 5,390
Recognized Expert Moderator Expert
hi ...
glad to hear you get it working ... post back to the forum anytime you have more questions ...
kind regards
Back one more time!!! XD.
Hi! again, I resolve the first problem but I have another one. My professor told me we want to catch te click event, I put the dmjpro's code and it works well with my code but with a little problem, I already catch the click event and the links too, but when I try to know or shows the URL of the clicked element, appears all the URLs of the other links if we have more than one. This is my code:
[HTML]<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.red_text {
color:#600;
}
.green_text {
color:#060;
}
.blue_text {
color:#006;
}
</style>
<!----The script!! XD--------->
<script type="text/javascript">
window.onload=f unction() {
els=document.bo dy.getElementsB yTagName('*'); <---!This is for get the "a" tags>
<!--This is for get every tag into the document, I guess XD-->
for(c=0;c<els.l ength;c++){
els[c].onclick=functi on(){
<!--Calling the fuction for clicks-->
getOnclicks(thi s.tagName,this. id,this.classNa me);
}
}
}
function getOnclicks(el, id,cl) {
<!--variable for get all document's links-->
var links = document.links;
if(id==''){
id='it has no id set';
}
if(cl=''){
cl='it has no class set';
}
<!--This condition just pass everything!!, so I don't know if I can filter the "a href" tags-->
if(el){
<!--dmjpro's code>
for(var i=0;i<links.len gth;i++)
<!--Here is the problem, I suppose this alert gets every "href" XD-->
alert(links[i].getAttribute(' href'));
}
}
</script>
</head>
<!--The HTML document to testing the script-->
<body>
<!--Here I didn't use tha class and id, this code was taking for an example in the Web XD-->
<h1 id="header" class="red_text ">header</h1>
<div id="foo" class="green_te xt">some text</div>
<div class="blue_tex t">some more text</div>
<div id="image_conta iner"><img id="my_image" src="my_image.g if" alt="my_image"/></div>
<!--links-->
<a href="http://www.uv.mx" id="hyperlink"> UV</a>
<a href="http://www.google.com" id="hyperlink"> Google</a>
<a href="http://www.yahoo.com.m x" id="hyperlink"> Yahoo Mexico</a>
<a href="http://www.itsx.edu.mx " id="hyperlink"> Tec Xalapa</a>
</body>
</html>[/HTML]
Thank's again!!!
acoder 16,027
Recognized Expert Moderator MVP
Please use code tags when posting code:
[CODE=javascrip t]
JavaScript code here...
[/code]
[CODE=html]
HTML code here...
[/code]
This thread is years upon years old and dead, but I stumbled upon it after a search and just had to say how impressed I was with the posts here. In most places, you wouldn't get such helpful posts but mockery considering the simple nature of the question. You guys are awesome.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Justin Koivisto |
last post by:
OK, I found a thread that help out from a while back (Oct 9, 2002) to
give me this pattern:
`(((f|ht)tp://)((+)(+)?@)?()+(:\d+)?(\/+)?)`i
OK, all is well and good with this until the URL is used at the end of a
sentance. I am assuming that I will need a negative lookahead somehow,
but I just can't wrap my mind around this one...
Want to match only the URL...
|
by: Philip Herlihy |
last post by:
I'm using a number of hyperlinks on an Intranet I'm developing which refer
to documents on a network server. The URLs I'm using have the form:
file://<server>/<path>/<file>.pdf
<server> is an UNC path, like: \\hostname
They work perfectly in IE, but not in Opera or Firefox. I can't see any
reason why not - is the form correct? Any other ideas?
--
|
by: Mark Rae |
last post by:
Hi,
I've been asked to write an ASP.NET app which uses traditional hyperlinks
with querystrings for navigation e.g.
http://<site>/customers/customer.aspx?id=123
The client wants the querystrings to be encrypted, sort of like Amazon.com
does. That's fine - no problem there.
However, the client now asks if there is any way of detecting whether the
|
by: MARTIN LANNY |
last post by:
Hi All,
In my program I am loading the content of a text file (main.txt) into a
string called 'message'.
What I need is to convert all urls and emails in this string into html.
This is what I did to convert hard returns to <br>'s and it works fine:
Dim sws As New IO.StreamWriter(pathtosave)
|
by: laredotornado |
last post by:
Hello,
I want to take a block of text and add html tags to make hyperlinks
where hyperlink strings exist. So, if I have a variable
$a = "This is http://www.yahoo.com"
I would like to run that through a function such that the value of $a
is
| |
by: Seefor |
last post by:
Hi, I want my text hyperlinks to have a dotted border underneath, so I did
this which works fine:
a,
a:link,
a:visited,
a:hover,
a:active {
color: #000;
text-decoration: none;
|
by: Robin |
last post by:
Hello!
I'm having trouble with links and hyperlinks in MS Access 2003 - any
help would be great!
Question 1!
The "insert hyperlink" icon opens a browser window, allows the user to
browse to the desired file and paste the hyperlink on the form (which
obviously remains for on all the records). I am trying to create a
|
by: Janna |
last post by:
Hello tech savvy gurus! I hope someone can help me!
THE PROBLEM:
"Cannot open specified file" when I click on a hyperlink in an Access database when it is located on our server.
THE BACKGROUND:
I created a folder "Document Library" on my local drive, which contains document sub-folders and the database.
For referential integrity, I designed the database with relative hyperlinks (e.g. Folder\File.pdf). The hyperlinks worked perfectly...
|
by: =?Utf-8?B?UGF1bA==?= |
last post by:
I have a web app that allows the user to create a list of urls. I am
currently have a textbox the user inputs the URL in one at a time and then a
button that when clicked adds the link to a dropdown list. Then for the
dropdown selected event I set the URL of a link button to the selected value
in the list.
Just wondering if you can have a dropdown list of hyperlinks? thanks!
--
Paul G
Software engineer.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |