Skip to content
Advertisement

Is an href=mailto the end of code execution?

I am modifying an old website, and I have run into an issue with javascript. I was hoping somebody could help explain it to me. In this website, there is a location.href="mailto:..." statement. After the mailto, there is some code that is expected to run. In older versions of this website, this code would run properly, but in my version, the code seems to stop running after the mailto. Is there something about this statement I don’t understand? Is this normal or does this mean there something wrong with my code?

The website is in php language. Here is some sample code.

<script type="text/javascript">
    location.href="mailto:test@example.com";
    document.write("echo")
</script>

The echo statement won’t run, and anything in php after the closing script tag won’t execute either. Ex: <?php echo "hi"; ?>

Advertisement

Answer

Setting location.href may halt all JavaScript and HTML processing, depending on the browser (and I wouldn’t be suprised if all major browsers handle this the same way). However, it will never stop PHP execution.

It may be hard to tell that your PHP kept running past the point where your JavaScript and HTML stopped, but you can test this by writing to a file: your PHP script will have no trouble creating a file on your server (provided it has the right file permissions), despite it having reached a point where the browser is ignoring its output.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement