javascript alert does not showup on my handy - javascript

when I test the following code in a browser like firefox it works perfectly well. When I transform it to an apk via Quick-App and put this apk on my samsung-handy, I will see the button but the alert does not show up.
Are there any settings on the handy that may prevent such popups or what might be the reason that the alert does not showup?
Thanks!
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("Hello");
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Show alert box" />
</body>
</html>

Related

I need to click on 'OK' buttom from ALERT on Internet Explorer with Selenium

I need to click on 'OK' Buttom from Alert on Internet Explorer. I tried use drive.switch_to.alert().accept()/.send_keys(Keys.ENTER) on Selenium Webdrive with Python, but it's not working.
How can I focus on this alert and do something to close it.
The alert happens before click on this button:
<input name="btn_gerar" id="btn_gerar" type="button" onclick="geraRelatorio()" value="Gerar relatório" class="botao" style="">
I suggest you first move the control from the web page to the alert popup and then try to accept it. That way it is working fine on my side.
HTML code:
<!DOCTYPE html>
<html>
<head>
<title>demo</title>
</head>
<body>
<input name="btn_gerar" id="btn_gerar" type="button" onclick="geraRelatorio()" value="Gerar relatório" class="botao" style="">
<script>
function geraRelatorio() {
alert("Hi!, I am a Simple Alert. Please Click on the 'OK' Button.");
}
geraRelatorio();
</script>
</body>
</html>
Python code:
from selenium import webdriver
driver = webdriver.Ie(executable_path='Path_to_web_driver...\\IEDriverServer.exe')
driver.get('https://Your_website_URL_here...')
driver.implicitly_wait(1)
alert_obj = driver.switch_to.alert
alert_obj.accept()
#driver.quit()
Output:
Make sure that code to close the alert() get execute after alert() is displayed on the screen. Sometimes code gets executed first and after that alert() gets display so the user thinks that his code is not working.

Setting time input with jquery does not work in mobile

I have a simple html code that sets the value of input of type time in document ready function. it works in computer browser correctly. but it does not work in mobile devices.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
</head>
<body>
<input type="time" id="time" style="height:25px">
<script>
$(document).ready(function (){
$("#time").attr("value","23:30");
});
</script>
</body>
</html>
while raw javascript works perfectly (below code):
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
</head>
<body>
<input type="time" id="time" style="height:25px">
<script>
$(document).ready(function (){
document.getElementById("time").value = "23:30";
});
</script>
</body>
</html>
any idea?
I did some search on Google and Mozilla has a great explanation about <input type="time">. some mobile browsers like Safari does not support this input yet.
As mentioned above, Safari and a few other, less common, browsers don't yet support time inputs natively
Source
this code behaves like time input on my mobile phone. use val method instead att.
$(document).ready(function (){
$("#time").val("23:30");
});
let me know if this helps you.

In Javascript setting a textarea with focus() does not work if called as a child window

I have a simple test page that sets the focus to a textarea on an oninit function. However the exact code fails to do this if the page is called as a child.
Putting alert box proves that the oninit function is being called but fails to put the focus in the textbox. Pressing reload though does then focus correctly.
So given that my code works perfectly when called on a main page, and also works in a child if reload is called, then why doesn't it work the first time?
<html>
<body onload="init()">
<script type="text/javascript">
function init()
{
document.getElementById("message").focus();
}
</script>
<textarea id="message" rows=10 cols=40></textarea>
</body>
</html>
Nothing clever here as you can, just only doesn't work if the page is loaded by window.open("test2.html");
You can also use setTimeout irrespective of the event.
setTimeout(function() {
document.getElementById("elementId").focus();
}, 0);
which browser do you use?
I check in firefox, chrome & IE.
Your code runs perfect and focus on the textarea.
I create two file test1.html and test2.html in a same directory.
In test1.html i insert the the follwing code..
<html>
<body>
<script type="text/javascript">
function init()
{
window.open('test2.html');
}
</script>
<button onclick="init()">test</button>
</body>
</html>
And in test2.html..
<html>
<body onload="init()">
<script type="text/javascript">
function init()
{
document.getElementById("message").focus();
}
</script>
<textarea id="message" rows=10 cols=40></textarea>
</body>
</html>
Than, I run the test1.html and click the button and test2.html appears with focus on the textarea.

Get selected text on IPad 2 with Javascript

I'am developing a web-application that allows to select parts of an html document and put some kind of annotation on it.
To get hold of the selected text I use window.getSelection() which works pretty fine in IE9, FF, and Safari.
However I run into trouble when using the same page on my IPad 2:
If I just select a word by tapping it for a sec, window.getSelection() returns the proper selection.
If I create a text range ( as discribed here http://blog.laptopmag.com/how-to-select-copy-and-paste-text-on-the-ipad ) always return "null".
I've already examined the window, document and related event objects - but without success...
Any help would be really appreciated!
Edit: Just a small example. Select a text and press the button. On Safari (PC) the function prints the selected value...
<html>
<body>
<script>
function a()
{
alert(window.getSelection());
}
</script>
Hello World! <input type="button" onclick="a();"
</body>
</html>
Okay finally I've solved the problem: As Tim assumed the click events causes to selection to collapse. I consider this as rather strange behavior as on regular Safari this does not happen.
However, the solution is not to use the click event. Instead of I'm using "vlick" provided by the jquery mobile.
Full working example:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body>
Hello World! <input type="button" id="button1" />
<script>
function a()
{
alert(window.getSelection());
}
$("#button1").bind("vclick",a);
</script>
</body>
</html>

JQuery - Write to opener window

I have an HTML page that opens another page via JavaScript. When a user clicks a button in the other page, I want to post a message in a DIV of the opening page via JQuery. I cannot put my finger on it, but I cannot seem to get this to work. Here is my opener page
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
</head>
<body>
<input type="button" onclick="window.open('dialog.html', '_blank', 'height=200, width=300');" value="launch!" />
<div id="testDiv"></div>
</body>
</html>
When the user clicks the "launch!" button, a dialog will appear. The code for the dialog looks like this:
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
</head>
<body>
<input type="button" onclick="updateOpener()" value="Update Opener" />
<script type="text/javascript">
function updateOpener()
{
var testDiv = window.opener.jQuery("#testDiv");
if (testDiv != null) {
alert("here");
testDiv.html("Updated!");
}
}
</script>
</body>
</html>
Surprisingly, the alert box appears. However, I cannot seem to update the HTML of the DIV in my opening page. Does anyone know how to do this?
You're referencing "confirmDiv". Where is that DIV?
You can't do that if the parent page (the opener) resides on another domain. Otherwise, your code works perfectly.
Also, your != null check is probably not doing what you think it is doing, as the jQuery function never returns null. If you are checking for the existence of an element, you need to do it this way...
var el = $("#myElementId");
if(el.length == 0)
alert('Not found!');
Ummm, it works for me in Firefox 3.0.11, IE8 and Chrome 2... (I.e. the dialog.html button updates the HTML in the opener page to say 'Updated!'.)
Oddly, your example works fine for me in Chrome, IE 8 and FireFox. Do you have any other details?

Categories