-2
I have seen similar questions here in the OS, but I still can not solve the following situation, where I have the function below that is inside an external script:
function updateScript(marcador, a, b) {
var head = document.getElementsByTagName('head')[0],
script = document.createElement('script');
script.type = 'text/javascript';
script.id = widget_config.script_id;
script.src = widget_config.home_page + '/feeds/posts/default/-/' + marcador + '?alt=json-in-script&start-index=' + a + '&max-results=' + b + '&callback=grabList';
if (document.getElementById(widget_config.script_id)) {
var oldScript = document.getElementById(widget_config.script_id);
oldScript.parentNode.removeChild(oldScript);
}
head.appendChild(script);
}
My purpose is, within my HTML file, to add a different value to the variable marcador
depending on where I call the possible function that passes this string to the marcador
. Ex.: Somewhere, I want to define the text CSS as the marker; in another, the text HTML, and so on.
In case, my HTML is like this:
<script src="endereço-do-script-acima.js"></script>
<script>updateScript("nome-do-marcador")</script>
It is possible?
You don’t do that, it doesn’t make sense, you probably want to do something else. If you do, I’ll come back later.
– Maniero
All right, @Maniero If you can help me, man, I’m grateful!
– winiercape
Setting as function parameter will not suit you?
– GeekSilva
@Geeksilva I tried as parameter but it didn’t work. I updated the question to make it clearer how my code is so far.
– winiercape
Has any Exception been launched? I still don’t quite understand the goal.
– GeekSilva
My intention, in fact, is to avoid repeating a large number of code, @Geeksilva . I have 8 Divs to show in each of the publications of a certain marker. I have a script that does this "categorization", because I just put the name of the marker inside the variable script.src that works. Only I’m trying a way to isolate this variable with the name of the marker and make it dynamic, because otherwise I’ll need to use all the code 8 times, and if I change only this line, it solves my problem.
– winiercape
Now I understand. When using the parameter, what didn’t work?
– GeekSilva
@Geeksilva The console says the parameter was not found.
– winiercape
You’d have to put that code on JS Fiddle?
– GeekSilva
I can send, yes, @Geeksilva It seems I’ve discovered a possible reason for the error. It seems to me that the code only accepts an ordered list and a div with specific ID. I am doing the tests here and any news, warning. Thank you!
– winiercape
Beauty. Because it is very strange that he does not recognize the parameter.
– GeekSilva
@Geeksilva Really, man, the problem I’m having is that the code only works in one instance. I was able to isolate the variable marker, declaring it externally (which was my goal with the question), but I won’t be able to close the 8 Divs because the code merges these markers into a single DIV, but that’s another story. For all intents and purposes, the question itself already has an answer. Thank you very much for your helpfulness, boy!
– winiercape
Imagine. How much we need
– GeekSilva