473,804 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Obtain HREF's

57 New Member
Hi all,

Does anyone know how to get JavaScript to retrieve the hyperlinks that are stored on a page and then use them later on?

Thanks in advance
Mar 30 '08 #1
23 2095
rohypnol
54 New Member
Does anyone know how to get JavaScript to retrieve the hyperlinks that are stored on a page and then use them later on?
var anchors = document.getEle mentsByTagName( 'a');
for (var i = 0; i < anchors.length; ++i)
{
alert(anchors[i].getAttribute(' href'));
}
Mar 30 '08 #2
wangers16
57 New Member
and how could I use this to display or manipulate the link when that link has been clicked?

e.g. if the user has clicked upon a link which was stored in an array then he/she would be redirected and if not then they would go to the specified page

http://www.thescripts.com/forum/thread700874.html, this is what I am currently using atm which requires me to add the following to all href's:

javascript:vali date('someurl')
Mar 30 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Add the validate function using onclick rather than as a href, i.e. when you loop over the links, add an onclick which passes this.href to the validate function.
Apr 1 '08 #4
wangers16
57 New Member
yes, but I would like it to be able to validate simply from this <a href="someurl"> text</a> alone.

Is this possible and if so how?
Apr 1 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
No, you will need to use some JavaScript code to detect clicks and deal with them.

You can make it unobtrusive - separate the JavaScript from the HTML - if that's what you want.
Apr 2 '08 #6
wangers16
57 New Member
ok

how can this be achieved?
Apr 2 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
What rohypnol posted, but set the onclick of each anchor in the loop and the function should be called after the page has loaded:
Expand|Select|Wrap|Line Numbers
  1. anchor.onclick = function() {
  2. // call validate() here
  3. }
Apr 2 '08 #8
wangers16
57 New Member
I have tried what you said with the following:

Expand|Select|Wrap|Line Numbers
  1. var anchors = document.getElementsByTagName('a');
  2. for (var i = 0; i < anchors.length; ++i)
  3. {
  4. anchors.onclick=function(){
  5. validate(anchors[i].getAttribute('href'));
  6. }
  7. }
  8. function validate(url){
  9. outlink = url
  10. if (pages.contains(outlink)==true){
  11. outlink = errpage;
  12. }
  13. window.location.href=(outlink)
  14. }
  15.  
however it doesn't seem to work, have I coded it correctly?

I have also included the function that checks the url as well in case it is needed
Apr 2 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
That should be anchors[i].onclick...
Apr 2 '08 #10

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

Similar topics

2
10287
by: midwesthills | last post by:
Is there a way to obtain the relative path of an image through javascript? I'm using document.imageName.src right now, and all I get is the absolute path. Thanks in advance for the help!
14
2515
by: Brandon Hoppe | last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is for Netscape 4 only. For example, here is the main page: <html> <head> <script type="text/javascript">
7
7341
by: Sam | last post by:
Hi, I can use System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() to obtain the path for ILASM.exe, but how can I obtain the path to ILDASM.exe? Examples of the path I'm looking for are: VSNET 2002 - "C:\Program Files\Microsoft Visual Studio ..NET\FrameworkSDK\Bin" VSNET 2003 - "C:\Program Files\Microsoft Visual Studio .NET
2
9185
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display in the status bar 'Symantec Corporation' whenever anyone mouses over (onMouseOver) my image or link OR when one clicks while holding the left mouse down (onClick) on the same image or link. Upon releasing the mouse (onMouseOut), the
4
5922
by: Rithish | last post by:
Is there a way to obtain the height of a <SELECT> element dynamically, i.e. through javascript? I want to dynamically display a list box onFocus of a text box element. Also, if the list box would move out of the bottom screen area, I would want to move it up by that fraction so that it displays at the bottom of the screen. To do this, I would need to acquire the height of the SELECT element. I tried quite a few methods. ...
8
8248
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) { document.location.href = document.location.href.substring(0, document.location.href.indexOf('#')) + '?' + newUrl; } else { document.location.href = document.location.href + '?' + newUrl; }
5
6711
by: Jeronimo Bertran | last post by:
Hello, We have developed a socket tcpip server in .net that accepts calls from clients. Using the connected socket we are able to use the Socket.RemoteEndPoint to obtain the IP address of the client. Is there any way to obtain the MAC address for the client? Thanks Jeronimo
5
18711
by: Kevin Myers | last post by:
How can one obtain obtain the height of a MS Access 2K form? There is a width property, but I don't see a corresponding height property. I need to obtain the height of the form so that I can dynamically resize an object on the form in the form's Form_Resize method when a user resizes the form, both horizontally and vertically. Thanks, s/KAM
2
2494
by: ME | last post by:
How would one obtain the parameter VALUES of a method that has already run? I can find the method using the StackTrace and StackFrame classes but once I find the method I would like to obtain the value of one of the parameters that were passed to the method. Is this possible? Even if I have to use PInvoke to do so? I can currently find the parameter TYPEs using reflection but I can not figure out to obtain the values. Thanks,
0
9591
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,...
0
10594
Oralloy
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...
0
10087
tracyyun
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...
1
7631
isladogs
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...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.