1

I'm working on a script made for a forum. The forum consists of several pages, and every page on the forum looks like this:

www.blabla.com/forum#p1
www.blabla.com/forum#p2
www.blabla.com/forum#p3
...
www.blabla.com/forum#p220

In my script, I have to find a specific URL on page 220, and if it's there, open it. The problem is, opening the link didn't seem to work like i want it to:

var elem = document.getElementsByClassName("all_items"), 
    i = 0;

if (elem[i].href.indexOf("www.blabla.com/item220") === 0)
    {
        window.open(elem[i].href, "_blank");
    }

What I'm doing here is: I first define all items on the page by their class, and then ask it to cycle through items until it finds the link of "item220" and opens it.

Problem: The only elements and links that figure inside the source code of this website, are those of page 1. As a result, my script can't find "www.blabla.com/item220" because this isn't on page 1, and therefore also not in the source code. Though, in the "inspect element" menu, I can indeed find the link of item220.

How do I find a link which doesn't exist in the source code but does appear inside the "inspect element" menu?

Thanks for helping me out,

-Bram

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
bram
  • 99
  • 2
  • 11
  • 2
    This means the content is JS-inserted, i.e. it is injected into the DOM, not part of the physical source code compiled on the server. – Mitya Mar 30 '14 at 21:36
  • Thanks, that makes sense. So is there any way to, inside my script, refer to the link that was JS-inserted? – bram Mar 30 '14 at 21:46
  • 2
    Your JS will be uncaring and unaware of whether links were in the source code or injected later; it sees only the current DOM. So if it's in there, by virtue of source code or injection, JS can find it. The source code vs. injection thing here is a non-issue for you. – Mitya Mar 30 '14 at 21:48
  • Wait so what you're saying is my script should be able to find it? – bram Mar 30 '14 at 21:57
  • 2
    If it's in the page - regardless of whether via source code injection - then yes. – Mitya Mar 30 '14 at 21:58
  • Thanks. Could it be that my script runs too early, and because the elements are injected after, it doesn't see them? – bram Mar 30 '14 at 22:08
  • 1
    Yes that was indeed the problem. The script was running too early and therefore wasn't doing it's job. A setTimeout fixed the problem. THANKS SO MUCH FOR YOUR HELP<3. – bram Mar 30 '14 at 22:17

1 Answers1

0

if something is dynamically added on a page it only appears in the 'inspect element' area and not the source code as the source is the webpage as it was loaded initially. Whereas the inspect element window shows you live changes on your webpage.

Anubhav
  • 7,138
  • 5
  • 21
  • 33