从浏览器地址栏执行 Javascript 方法 - GWT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18782297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 13:13:23  来源:igfitidea点击:

Execute Javascript method from browser address bar - GWT

javascriptgwt

提问by quarks

I'm trying to execute Javascript on my web application by executing this on the browser URL/address bar:

我正在尝试通过在浏览器 URL/地址栏上执行此操作来在我的 Web 应用程序上执行 Javascript:

javascript:window.alert('test');void(0);

However, nothing happens and the alert box is not showing up? Could the reason be that the app is running in DevMode?

但是,没有任何反应并且没有显示警报框?原因可能是该应用程序在 DevMode 下运行?

采纳答案by Thomas Broyer

I believe most browsers refuse to execute javascript:URLs from the URL bar as a safety measure (there's been messages on the web –esp. Facebook– telling people to copy-paste a javascript:URL to their URL bar that triggered an XSS). They didn't want to break bookmarklets though, so you can put that code in a bookmark; but it's much easier to just open the browser's JS console and type that command there.

我相信大多数浏览器都拒绝javascript:从 URL 栏执行URL 作为安全措施(网络上有消息 - 尤其是 Facebook - 告诉人们将javascript:URL复制粘贴到他们的 URL 栏中,从而触发了 XSS)。不过,他们不想破坏书签,因此您可以将该代码放入书签中;但是打开浏览器的 JS 控制台并在那里输入该命令要容易得多。

Anyway, it's not due to GWT's DevMode.

无论如何,这不是由于 GWT 的 DevMode。

回答by LJRKUMAR

You can write your javascript code inside the block like this

您可以像这样在块内编写 javascript 代码

javascript:{alert("ok");}