How to get the final result of javascript? [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have an html page with a lot of javascript code, for example the content of a div depends on length of an array :
for (var i = 0; i < movieList.length; i++) {
document.body.appendChild(document.createElement('h2')).appendChild(document.createTextNode('title: ' + movieList[i].title));
var cUL = document.body.appendChild(document.createElement('ul'));
cUL.appendChild(document.createElement('li')).appendChild(document.createTextNode(movieList[i].rating));
cUL.appendChild(document.createElement('li')).appendChild(document.createTextNode(movieList[i].year));
cUL.appendChild(document.createElement('li')).appendChild(document.createTextNode(movieList[i].length));
cUL.appendChild(document.createElement('li')).appendChild(document.createTextNode(movieList[i].isComedy));
cUL.appendChild(document.createElement('li')).appendChild(document.createTextNode('main characters: ' + movieList[i].mainCharacters.join(", ")));
}
I am using these perl LWPx::ParanoidAgent and HTML::TokeParser modules to handle the HTML code but the i want the result of the javascript script

You either need to:
Reverse engineer the JS and apply the changes it would make manually or
Run the HTML and JS through a browser or browser-like tool and read the data from its DOM
There are a number of options for the latter, including WWW::Mechanize::Firefox, WWW::Selenium and Wight.

perhaps https://getfirebug.com/ is what you're looking for. Amongst loads of other things you can view your HTML after JavaScript has altered it.

Related

Is there a way that this is possible? I am trying to find a value of a var constructed by other variables [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
This is a little bit of my code. I took out the complex parts. It is all on the script tag.
var trueenemyscoutx = '_2'
var tryeenemyscouty = '2'
var type_22 = "none"
var move1;
enemymove = "type" + trueenemyscoutx + trueenemyscouty;
var move1 = (enemymove.valueOf()).valueOf()
In the post, enemymove is a string constructed by concatenating "type" and two other variables, each of which is also a string.
The resultant string contains no information about the variables used and so the general answer to the question is no, it is not possible using the approach taken.
Obvious alternatives include:
Keep move a string, but use a separator (e.g. colon, comma or space) between component substrings. This allows extracting an array of the components using move.split(separator).
Use an array or simple object to hold move information instead of a string in the first place.

How to show method declaration in NodeJs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
is there any way to show function declaration. e.g what it takes as parameters and what it returns in CLI? as like "tinker in laravel"
I searched over internet but found nothing.
I am not sure if I correctly understand your question. To find out what a function looks like, including its parameters (and all its code including what it returns), you can do a (slightly dirty) hack like this:
function a(b,c) {
return b + ", " + c;
}
console.log(a.toString());
Output:
'function b(a,b){return a+" " + b}'
Alternatively, if you are looking for documentation, for most NPM modules and note itself, there is solid API documentation. See https://nodejs.org/api/ for example.

how to pass a variable to queryselectorAll? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Hi I want to pass a variable to queryselectorAll. I tried a couple of things but non have worked for me. I'm doing that because in my code I change the variable to a new one every time a click a button.
var container = document.getElementById(containerBox.id)
// I want containerBox.id to be called in querySelectorAll
templateDiv = document.querySelectorAll('#' + 'containerBox.id' + 'template')[0].content.firstElementChild
Thanks in advance
This question can be simplified to: How do I construct a string from fixed parts and a variable part?
The answer to that is:
'#' + containerBox.id + 'template'
(i.e. just don't put quotes around your variable name).
But why bother using .querySelectorAll() just to grab the first index? You could simply call .querySelector() instead.
And if all you need to get is an element with a specified id, you can just do this:
document.getElementById(containerBox.id + 'template')
... which is the method you're already using in your first line.

How to ask in Javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to write a line of code which asks a question and the user has to enter a number. The number is then stored as a variable and used throughout the rest of the script. Such as:
fit1 = "What is your fitness level?"
level = the number the user had entered
something like that. Can't really explain it properly
P.S. I'm writing my code out in gedit because thats what my uni uses.
You can use a prompt like shown below:
var n = prompt("Fitness level");
console.log(n);
window.level = window.prompt('What is my fitness level?');
console.log(window.level); //save in glonal space of window
You can use the Prompt command, and cast the string answer to type number :
var number = parseInt(prompt('Give me a number', '0'));
alert('You said: ' + number);

setInterval Chrome vs Firefox [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a Javascript setInterval function that works in Chrome, but not in Firefox. It is supposed to keep writing a string every so often on the screen. I know document.write is not a prefer method. Here is the code:
function doSomething(){
document.write("1st string ");
}
setInterval(doSomething, 2000);
Thank you (JS newb).
When using document.write in firefox, you need to have document.open it first, you can read about it on MDN
Also, no one uses document.write anymore, and if they do, that is just redundant.
If your target is just to write strings into the body, use something like this:
function safeDocumentWrite(text) {
document.body.appendChild(document.createTextNode(text));
};
or alternatively if you want to append HTML, wrap it in a <div> first:
function safeDocumentWrite(html) {
var div = document.createElement('div');
div.innerHTML = html;
document.body.appendChild(div);
}

Categories

Resources