0

Using Firebug I have extracted all the links of a web page using:

var links = document.getElementsByTagName("a");
for(var i=0; i<links.length; i++) {
    console.log(links[i].href);
}

now all the links are in the console and they are in the format:

javascript:tenderLog1('abcd.pdf','test','23');

Now I want to pass this string output as a Firebug js command so that all the links get opened automatically.

Is there any function to pass js variable as a Firebug command?

5
  • You should probably explain your underlying intention, as what you describe you want to accomplish does not make much sense. Commented Jul 1, 2012 at 16:38
  • i mean lets say i got the string javascript:tenderLog1('abcd.pdf','test','23'); from the webpage. Now i need to pass this string as a firebug command so that the respective tenderLog1 function is called Commented Jul 1, 2012 at 16:42
  • If there is no such command, can u please tell me the regular expression so that i can get the 3 arguments from the string. From there i can call the function manually. Thanks Commented Jul 1, 2012 at 16:45
  • 2
    @SuryaKLSV The easiest solution is to define a function tenderLog1, and use eval on that string. Another method is (NO REGEXES!) to get the contents within the parentheses, wrap it in [, ], and use JSON.parse. Commented Jul 1, 2012 at 16:48
  • javascript:tenderLog1('abcd.pdf','test','23'); is not a "firebug command", whatever that would be, so there would not be a way to "pass it" as such. It is an URL. It really makes no sense; you can open URLs using window.open, though I think some browsers restrict javascript: URLs nowadays. Commented Jul 1, 2012 at 22:25

1 Answer 1

1

It's a bit hard to guess what exactly you want to achieve. I guess that you want instead of

console.log(links[i].href);

to do

eval(links[i].href.replace("javascript:",""));

? This would be equivalent to invoking tenderLog1('abcd.pdf','test','23') from Firebug console in the example you've provided. The outcome depends on what tenderLog1 functions does of course.

But perhaps it would be cleaner to see what the function does (window.open?), and provide commands after parsing the parameters with some regular expression.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.