Prevent reloading a website after sweetalert

76
February 13, 2020, at 00:50 AM

On a web page there is a table with a few rows. In each line there is a button that triggers a Javascript function:

PHP/HTML:

echo "<form action='' method='post'>";
echo "<button type='submit' name='test' value=".$row[4]." class='attest btn btn-info btn-round btn-icon btn-icon-mini btn-neutral' data-original-title='Test'><i class='now-ui-icons files_single-copy-04'></i></button>";
echo "</form>"; 

PHP:

if(isset($_POST['test'])) 
{
    $file="/files/".$_POST['test'].".jpg";
    $caption="Image: ".$_POST['test'];
    if (file_exists($_SERVER['DOCUMENT_ROOT'].$file)) 
        {
            echo"<body onload='showtest()'>";
        } 
    else 
        {
            echo"<body onload='notest()'>";
        }
}

JS:

function showtest()
{
 swal({
  title: 'Image',
  text: <?php echo json_encode($caption); ?>,
  imageUrl: <?php echo json_encode($file); ?>,
  imageWidth: 400,
  imageAlt: 'Image',
})
}
function noattest()
{
swal({
  title: 'Image',
  text: "There is no image.",
  icon: 'warning',
})
}

A dialog is then displayed using Sweetalert2. The problem is that the table contains so many records that the web page must be scrolled. As a result, the alert is displayed correctly, but the web page "scrolls up again"/reloads. This is very annoying, because you have to search for the right row in the table again.

Is there a solution so that the web page does not jump to the top?

READ ALSO
How to use javascript to put volume to 0 or close current tab for twitch or just mute the chrome tab?

How to use javascript to put volume to 0 or close current tab for twitch or just mute the chrome tab?

i am making a google chrome extension and currently, i want a function that either close the twitchtv tab or put volume of the stream to 0 is it possible or maybe the best way would be to mute the chrome tab

41
How to prevent page refresh on browser back to page generated by ajax call

How to prevent page refresh on browser back to page generated by ajax call

Is there a way to push the ajax call result? I don't understand where the actual state of the result page is storedBecause history

50
Styling issue with React App after refreshing

Styling issue with React App after refreshing

I made a React Color Picker App following React Udemy course by Colt SteeleI am facing some weird issue in my app with styling and I can't figure out what's causing it

39
WebView inject Javacript = Error 0x80020101

WebView inject Javacript = Error 0x80020101

I downloaded a website to local filesystem to try inject some javascript code:

76