• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 890
  • Last Modified:

GetElementsByName? ?

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
     next
-->
</script>

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:\\development.training.com\respond test.asp?LogUser=" & user & "&LogSubject="

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

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

I have a line in my ASP that replaces "../" with "www.training.com\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?

                PvBredow
0
PvBredow
Asked:
PvBredow
1 Solution
 
smidgie82Commented:
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.
0
 
PvBredowAuthor Commented:
Thanks for the explanation!

      Pvbredow
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now