Execute Javascript method from browser address bar - GWT

血红的双手。 提交于 2019-12-20 12:34:30

问题


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

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?


回答1:


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.

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




回答2:


You can write your javascript code inside the block like this

javascript:{alert("ok");}


来源:https://stackoverflow.com/questions/18782297/execute-javascript-method-from-browser-address-bar-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!