Как вручную ввести скрипт для тестирования на инструментах разработчика Firebug или Chrome

240
Vandervals

Я хотел бы проверить, как мой скрипт работает на разных сайтах. Интересно, возможно ли использовать инструменты разработчика для его выполнения? Я попытался добавить его в тег, но он не выполняется.

Кто-нибудь знает какой-либо другой метод?

(Я не уверен, что это правильный сайт. Я не думаю, что он имеет мало общего с программированием, и это больше о том, как использовать инструменты разработчика, поэтому я подумал об этих местах, а не переполнение стека )

Спасибо!

1

3 ответа на вопрос

1
Vandervals

I solved this by introducing this in the console:

var script1 = document.createElement("script"); var script2 = document.createElement("script"); var head = document.querySelector("head"); var text = 'myscript();'; script2[(script2.innerText===undefined?"textContent":"innerText")] = text; script1.setAttribute("src", "http://mysite.myscript.js"); head.appendChild(script1); script1.onload = function(){ head.appendChild(script2) }; 
1
fflorent

You may be interested in the Firebug's include() command.

Florent

Есть ли что-то похожее в Chrome? Vandervals 8 лет назад 0
AFAICT, нет. https://developer.chrome.com/devtools/docs/commandline-api#additional-apis fflorent 8 лет назад 0
0
Sebastian Zartner

The different devtools have editors allowing you to execute JavaScript code in them.

In Firebug this is the so-called Command Editor, the Firefox DevTools have something called Scratchpad. Those and the Chrome DevTools also allow you to write multi-line code by pressing Shift+Enter within their command lines.

Note: Scripts executed this way are just temporarily available within the page. After a page reload they are gone again.

Похожие вопросы