I have the same question, and it was not answered at all.
We are asking for a function that can be passed a URL and
returns a list of anchor tags. I do it in VB all the time.
We keep getting answers on how to get anchors from the page
we are on. If you are suggesting we go to the page to get the
document.whatever...
How can we run our scripts we left back on the page we left?
Asked
Active
Viewed 54 times
-1

DeiDei
- 10,205
- 6
- 55
- 80
-
You can certainly grab the entire DOM of a website with a simple AJAX request... but I've got no idea what you mean about returning a list of anchor tags. Are you asking how to return a collection of every `ID` on the target page? – Obsidian Age May 17 '18 at 03:18
-
like this: var myPage = function(some_URL) { someCode.. return(text) } – Keyzz Locks May 17 '18 at 03:23
-
results: texttexttext – Keyzz Locks May 17 '18 at 03:24
-
_“I have the same question, and it was not answered at all.”_ - if you are referring to an existing question, then you should give a link to it. Without context, there is no “same”. – CBroe May 17 '18 at 11:36
1 Answers
0
You can pass in arbitrary html to jQuery functions - so if using jQuery is acceptable, then try something like this;
$.ajax("https://example.com").done(function (data) {
let list_of_anchors = $(data).find("a");
});
This will fetch https://example.com
and then use jQuery to parse and find the a
tags for you. You can then do what you like with them.
If you are doing this, you may run into issues with cross-site scripting. Questions like this one have information on that topic.

Shadow
- 8,749
- 4
- 47
- 57
-
thank you. that helped. i learned that as a security feature, javascript cannot get pages outside of it's domain. my question was about the language, not how to accomplish the task. – Keyzz Locks May 17 '18 at 05:15
-
I'm glad it helped. Don't forget to tick the answer if it has helped you :) – Shadow May 17 '18 at 05:17