GetElementsByName? ?

Posted on 2006-05-31
Last Modified: 2012-05-05
I am posting this question to (hopefully) be answered by Smidgie82.      [Hope that isn't against the rules, but Smidgie was very helpful on an earlier question, but didn't eventually solve it, so the points were awarded to someone else.       This question is to allow me to more fully understand Smidgie's suggested technique, and also to award points I feel are appropriate for the effort they provided.        Anyone may answer if they wish, but I will be biased to accept Smidgie's answer, so other people prefer not to waste time replying to this]

In response to an earlier question, Smidgie82 suggested the following lines.

<script type="text/vbscript">
     myurl = "customlink"
     for each i in document.GetElementsByName("aspLink")
          i.href = myurl & i.href

What is 'aspLink'?        Is that a keyword for something, or would I need to replace that with something from my page?         Is this essentially a way of doing search&replace on all the href's in my document, so they are all preceded with the contents of my variable 'myurl'?         If so, this sounds like a very handy technique.

When I have myurl="http:\\\respond test.asp?LogUser=" & user & "&LogSubject="

and <a href="../Source Files/Data Editing.mht"  title="Data Editing" target="_new">

then it resolves into:
http:\\\onlinecourse\fip\spider\source files\data editing.mht

I have a line in my ASP that replaces "../" with "\onlinecourse\fip\spider\source files\", so I can see that it is using my ASP to resolve the resulting address, even before the hyperlink is clicked.

There is still something mysterious about this though.

When I use this approach, I end up seeing the correct page, in a new window, as desired.        The problem I face is that the logging is not taking place.       The ASP page should write a log entry on the basis of the querystring passed to the ASP, but this isn't happening.

I don't get any error messages at all, so it makes me wonder if perhaps what could be happening is that the ASP is being called only as far as determining what URL will result if it were run.      This sounds unlikely, but it seems to fit what I am observing.

With this technique, does the ASP file still get executed in full?

Question by:PvBredow
    LVL 9

    Accepted Solution

    I think this may be against the rules.   However, I'm sure the mods will notify you if so, and no harm done.  Here's a re-post of the final reply I made to the previous topic, before realizing the points had already been awarded:

    Yes, you are correct that this is a search-and-replace technique.  It gets an array of link objects, iterates through them, and replaces their href values with a new value.  You won't see the effect if you go to "view source", but you should see the effect in the rendered page (hover your mouse over a link and look at the status bar).

    I'm sorry, I included that "aspLink" part in order to distinguish the links you want to change from any you might not.  In the page I made to test this, I included a name="aspLink" attribute in all the links I wanted to test.  Then, the document.GetElementsByName() call will only adjust those links you've specifically tagged as wanting to replace.  If you don't need this functionality (i.e., you want the code to process ALL the links on the page), then you can replace document.GetElementsByName("aspLink") with document.links, and it should work just fine.

    It looks as though the substitution is not taking place correctly, which makes perfect sense in retrospect, as you likely haven't included the name="aspLink" attribute in the links (because I didn't think to describe its effect fully).  My apologies.  Either add that attribute, or make the change I suggested above (to make the change global to all links), and it should start working.

    Author Comment

    Thanks for the explanation!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Create Mobile App Prototypes with Adobe XD

    This is a project-based course: we go through all the steps of creating a prototype from start to finish, using all the tools and features currently available in Adobe XD. You can complete the course in less than a day, plus all project files and fonts are included.

    Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now