0
How can I disable all javascript alerts via web browser ?
When I’m loading the page.
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<meta charset="UTF-8">
<!-- Latest compiled and minified JavaScript -->
<script src="js/bootstrap.min.js"></script>
<script>
alert('Olá, bem vindo ao ultimo passo');
function nextStep()
{
setTimeout(function () {
window.location.href = "entrada.php"; //will redirect to your blog page (an ex: blog.php)
}, 2000);
}
</script>
<title></title>
</head>
<body onload="alert('Mas não tanto ao ponto de o botão de Finalizar tarefas não funcionar');alert('Boa sorte ;-)');">
<h1>5 - Injeção de JavaScript</h1>
<h2>Objetivo</h2>
<p>Essa página, como você deve ter percebido tem uma sequencia de Alerts,
o que necessitamos é que você clique em "OK" nos Alerts ou de um jeito
para que eles não aparecam mais</p>
<p style="width:500px;text-align:right;">
<input type="submit" id="Submit" name="Submit" value="Finalizar Tarefas" class="btn btn-primary" onclick="nextStep();">
</p>
<script>
alert('A Tarefa aqui consiste em barrar o Javascript');
</script>
</body></html>
She’s already face the Alert.
alert('Olá, bem vindo ao ultimo passo');
I tried to do it the way down, but I’m not getting it.
webBrowser.Navigate(url);
while (webBrowser.ReadyState != WebBrowserReadyState.Complete && webBrowser.Document == null)
{
Application.DoEvents();
}
var doc = webBrowser.Document.Window.Open(url, "", "", true);
HtmlElement head = doc.Document.GetElementsByTagName("head")[0];
HtmlElement scriptEl = doc.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
string alertBlocker = "window.alert = function () { }";
element.text = alertBlocker;
head.AppendChild(scriptEl);
head.InvokeMember("click");
Thread.Sleep(2000);
HtmlElement submit = doc.Document.GetElementById("submit");
submit.InvokeMember("click");
What I need is to click "OK" on the Alerts or in a way so they don’t appear anymore.
What is the context of these 'Steps'? Because it depends on the context for the application, in a simple way you can set a session or cookie stating that the Alerts have already been viewed and use an if to know whether or not they need to be shown again.
– AnthraxisBR
@Anthraxisbr, I don’t understand... what you’re talking about in context ...
– Marco Souza
Context is what these Alerts are, whether they are even for user interaction, or whether they are just page building information, but I think in any case record that they have already been seen in a cookie or in a session will already solve.
– AnthraxisBR
are user interaction, they are loaded as soon as the page opens in the browser.
– Marco Souza
if(localStorage.getItem('alert1') === '1'){ //nothing }Else{ Alert('Hello, welcome to the last step'); localStorage.setItem('alert1','1'); }. If you start a session for Alert, save a value and compare in the session if it exists, it will only be displayed again at the end of the session, see this excerpt I put here, replace the code of the first Alert with it, if that’s right I prepare a decent response.
– AnthraxisBR
the message is shown by the browser...and not on the page, you will need to use OS function to search for the message and click the button. I’ve done it and I’ve got the code, coming home public here
– Rovann Linhalis