473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to get urls from hyperlinks

manuelgk
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 #1
15 2773
dmjpro
2,476 2GB
Hi everybody, I just a total beginner using Javascript and I would like ti 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

Welcome to TSDN!
There is an attribute href of a Tag.
Try to access this.

Have an example.
Expand|Select|Wrap|Line Numbers
  1. var links = document.links;
  2. for(var i=0;i<links.length;i++)
  3.  alert(links[i].getAttribute('href'));
  4.  
Good Luck.

Kind regards,
Dmjpro.
Sep 13 '07 #2
Thank you, but as I say I'm a total beginner (hehehe) so my next question is where can I try it? XD.
Sep 13 '07 #3
epots9
1,351 Expert 1GB
Thank you, but as I say I'm a total beginner (hehehe) so my next question is where can I try it? XD.
on a HTML page with all the <a> tags with the name "links"
Sep 13 '07 #4
Death Slaught
1,137 1GB
Try going here it's a tutorial on javascript.
Sep 13 '07 #5
Thanks everybody, I follow all the advices and read the javascript tutorial, they were really useful. However, it seems like js only accept (as the first suggestion) the <a> tags with an specific URL in a Web page. My objetive is make a extension for a navigator (Mozilla), it should detect the hyperlinks no matter the web page I open. I need to take the URL's from the hyperlinks (as a status bar) and modify or send an alert before the client access the Web page. As I tell you before, the detection of the hyperlinks must be in any page of the Web. So I don't know if js is the correct option for do that or should I do it in another programming language?.
Thanks again for your help, and I'm sorry if I do stupid questions hehehe!
Sep 18 '07 #6
Death Slaught
1,137 1GB
Thanks everybody, I follow all the advices and read the javascript tutorial, they were really useful. However, it seems like js only accept (as the first suggestion) the <a> tags with an specific URL in a Web page. My objetive is make a extension for a navigator (Mozilla), it should detect the hyperlinks no matter the web page I open. I need to take the URL's from the hyperlinks (as a status bar) and modify or send an alert before the client access the Web page. As I tell you before, the detection of the hyperlinks must be in any page of the Web. So I don't know if js is the correct option for do that or should I do it in another programming language?.
Thanks again for your help, and I'm sorry if I do stupid questions hehehe!
Np it's what we're here for, and there's no such thing as a stupid question, we all had them once upon a time.

- Death
Sep 18 '07 #7
acoder
16,027 Expert Mod 8TB
Thanks everybody, I follow all the advices and read the javascript tutorial, they were really useful. However, it seems like js only accept (as the first suggestion) the <a> tags with an specific URL in a Web page. My objetive is make a extension for a navigator (Mozilla), it should detect the hyperlinks no matter the web page I open. I need to take the URL's from the hyperlinks (as a status bar) and modify or send an alert before the client access the Web page. As I tell you before, the detection of the hyperlinks must be in any page of the Web. So I don't know if js is the correct option for do that or should I do it in another programming language?.
Javascript would only work within the current page. How are you accessing the URLs? Can you give a complete example of hat you are trying to do? Also note that Javascript cannot be used for cross-domain scripting.
Sep 19 '07 #8
gits
5,390 Expert Mod 4TB
hmmmm ...

but for an extension you may retrieve the references and build up your own list ... even your own page from it ... so you may do whatever you want with that after 'making it your own' :) ... it could act like a content filter ... what i would assume that the extension should be for?

kind regards
Sep 19 '07 #9
Ok guys thanks for help me again, I was discussing with my professor about the possibility to create this, and we concluded that javascript is a language for extend the functionality of html, so the hyperlinks must have a reference (<a href></a>), thus, is impossible to be in a Web site or Web page if we don't know the direction. In other words, it happens when we want to know how a place look like and we'd never been in that place, even worse if we don't have the address, obius we never know exactly how it looks!!!, that's why we need references about where we want to go before modify something in the fuction. So my new question is how can I know the thing that I'm click is a hyperlink? do the event hadler (onmouseover, onclick) help me?
Thanks for your help again and I'm sorry if I cannot answer before... XD
Greetings from Mexico for every one!!!!
Sep 24 '07 #10
gits
5,390 Expert Mod 4TB
hi ...

when clicking something you may retrieve the event target, lets assume that you click a hyperlink the:

Expand|Select|Wrap|Line Numbers
  1. event.target.nodeName
  2.  
or:

Expand|Select|Wrap|Line Numbers
  1. event.target.tagName
is 'A'.

kind regards
Sep 24 '07 #11
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.!!!
Sep 25 '07 #12
gits
5,390 Expert Mod 4TB
hi ...

glad to hear you get it working ... post back to the forum anytime you have more questions ...

kind regards
Sep 25 '07 #13
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=function() {
els=document.body.getElementsByTagName('*'); <---!This is for get the "a" tags>
<!--This is for get every tag into the document, I guess XD-->
for(c=0;c<els.length;c++){
els[c].onclick=function(){
<!--Calling the fuction for clicks-->
getOnclicks(this.tagName,this.id,this.className);
}
}
}

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.length;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_text">some text</div>
<div class="blue_text">some more text</div>
<div id="image_container"><img id="my_image" src="my_image.gif" 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.mx" id="hyperlink">Yahoo Mexico</a>
<a href="http://www.itsx.edu.mx" id="hyperlink">Tec Xalapa</a>
</body>
</html>[/HTML]

Thank's again!!!
Sep 27 '07 #14
acoder
16,027 Expert Mod 8TB
Please use code tags when posting code:
[CODE=javascript]
JavaScript code here...
[/code]

[CODE=html]
HTML code here...
[/code]
Sep 27 '07 #15
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.
Oct 27 '10 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

22
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...
3
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...
5
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...
12
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...
2
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...
4
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;
1
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...
1
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...
4
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.