Perform click of html button?

Hello
In html file, i have a button "file-input" to run a function.

<!DOCTYPE html>
<html>
<head>
</head>
<body>

    <label for="file-input" class="file-input-label"></label>
    <input type="file" id="file-input" accept=".wexbim" onchange="checkAndLoad()">

    <script>

        function checkAndLoad() {
            if (models.length > 0) {
                for (var i = 0; i < models.length; i++) {
                    viewer.unload(models[i]);
                }
                models = [];
            }
			
            var file = document.getElementById("file-input").files[0];
			
            viewer.loadAsync(file);
            viewer.start();    	
        }
    </script>
</body>
</html>

Ho we can use a button in Appinventor to run the function of this html button?

To test the html button:
https://onecompiler.com/html/3zrqsqkun

Use the webviewstring to send a string to your script. The value of that string can indicate whether the function is run or not.

Thanks, i check your tutorial but i don't know how this work to prform a button click?

This button must open a dialog or a location (in Android) to load a file
<input type="file" id="file-input" accept=".wexbim" onchange="checkAndLoad()">

Simple example if your own html...

<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<head>
	<title>Doc Click</title>
	
</head>

<body>
	<button onclick="showdiv();">Click Here</button>
	<div id="show"></div>
	<script>
		if (window.AppInventor) {
			var wvs = window.AppInventor.getWebViewString();
			if (wvs = "click") {
				showdiv();
			}
		}
		//button click function!
		function showdiv() {
			document.getElementById("show").innerHTML = "I have been clicked by the webviewstring";
		}
	
	</script>
</body>

</html>

Otherwise you may be able to use something like THIS

1 Like

Thank you @TIMAI2
The solution from the link works excellent

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.