简体   繁体   English

如何在Chrome控制台中执行Javascript代码?

[英]How to execute Javascript code in Chrome console?

I have a little application that generates some Javascript code, what can be executed on websites. 我有一个小应用程序,可以生成一些Javascript代码,这些代码可以在网站上执行。 To execute this code I'm using browser console and for Firefox it works well, but I can't figure out how to make it work with the Chrome browser. 要执行此代码,我使用了浏览器控制台,对于Firefox,它可以很好地工作,但是我不知道如何使其与Chrome浏览器一起使用。

In Firefox I'm generating this Javascript code: 在Firefox中,我正在生成以下Javascript代码:

javascript:var els = document.getElementById('video');els.style="";var none = document.getElementById('slika'); none.style="display:none;"

I open the console (CTRL-SHIFT-K), paste it, press ENTER and then the code is doing it's job. 我打开控制台(CTRL-SHIFT-K),将其粘贴,按Enter,然后代码即可完成工作。 I tried with Chrome via console (CTRL-SHIFT-J), in the address bar, but nothing happens. 我尝试通过控制台(CTRL-SHIFT-J)在地址栏中使用Chrome,但是没有任何反应。 If I'm trying in the console all I get is this line: 如果我在控制台中尝试,我得到的只是这一行:

"display:none;"

What does it stand for? 它代表什么? Is there some syntax error? 有语法错误吗?

If i try in the address bar, the browser redirects me to google and executes a query with the javascript code as search value :) 如果我在地址栏中尝试,浏览器会将我重定向到google并执行以javascript代码作为搜索值的查询:)

So I'm stuck with Chrome... 所以我坚持使用Chrome ...

Can someone help me out, please? 有人可以帮我吗? Thank you very much! 非常感谢你!

You don't need the javascript: prefix if you're entering the code in the console. 如果您要在控制台中输入代码,则不需要javascript:前缀。

Also, I'm not sure if none.style="display:none;" 另外,我不确定是否none.style="display:none;" is valid. 已验证。 Try none.style.display="none"; 尝试none.style.display="none"; if you're having problems with it. 如果您遇到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从Chrome控制台执行Javascript - Cannot execute Javascript from Chrome console 如何使用Chrome开发人员工具执行一段JavaScript代码 - How to execute a piece of JavaScript code using Chrome developer tools 解密 JavaScript 代码并修改 Chrome 控制台? - Decrypt JavaScript code and modify Chrome console? 如何在Visual Studio Code预览侧打开Web控制台(例如Chrome控制台)并动态查看JavaScript更改? - How to open web console like Chrome console in Visual Studio Code preview side and see JavaScript changes dynamicaly? 从 Java 应用程序在 Chrome 控制台中执行 JavaScript 命令 - Execute JavaScript commands in Chrome Console from Java App Javascript在chrome控制台等网页上执行js - Javascript execute js on a web page such like chrome console Chrome控制台执行内容的方式与Visual Studio代码相同吗? - Does the Chrome console execute things the same way as Visual Studio Code? 如何在浏览器控制台中使用单行代码多次执行 javascript 命令? - How to execute a javascript command multiple times with single line of code in browser console? 如何通过 Chrome 浏览器开发者控制台中的 Javascript 代码关闭模态弹出窗口? - How to close a Modal Popup via Javascript code within Chrome Browser Developer Console? 如何在Chrome 70的Javascript控制台中禁用自动完成功能? - How to disable autocomplete in the Javascript console for Chrome 70?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM