G
G
gadertes2018-03-14 12:07:59
JavaScript
gadertes, 2018-03-14 12:07:59

How to get the contents of a script tag?

There is a local script attached to the document via a script tag - is it possible and how to copy the contents of this tag and paste it into another script tag?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniel, 2018-03-14
@daniil14056

Add id r to the script or find its selector

var script=document.getElementById("id-script");
var scriptTarget=document.getElementById("id-script-target");
scriptTaget.innerText=script.innerTarget; // скрипт не будет исполнен, так как этот элемент уже был загружен.
// более правильно будет создать элемент скрипта и добавить его на страницу
var s=document.createElement("script");
s.innerText=script.innerText;
document.body.appendChild(s);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question