Categories
JavaScript Answers

How to call JavaScript function from URL or address bar?

Spread the love

Sometimes, we want to call JavaScript function from URL or address bar.

In this article, we’ll look at how to call JavaScript function from URL or address bar.

How to call JavaScript function from URL or address bar?

To call JavaScript function from URL or address bar, we can type in a data URL.

For instance, we type in

data:text/html,<script>alert('hi');</script>

into the address bar to run the JavaScript code in the script tag.

Therefore, we see an alert box that shows ‘hi’ displayed when we type this in.

Conclusion

To call JavaScript function from URL or address bar, we can type in a data URL.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *