Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Call Javascript function from a URL

Is it possible to call a javascript function from the URL? I am basically trying to leverage JS methods in a page I don't have access to the source.

Something like: http://www.example.com/mypage.aspx?javascript:printHelloWorld()

I suspect the answer to this is no but, just wondered if there was a way to do it.

Answer*

Draft saved
Draft discarded
Cancel
6
  • 2
    i always thought data url is only for images, thanks this is really amazing :) Commented Sep 13, 2016 at 5:21
  • 11
    you can't append this to a url. Commented Feb 25, 2019 at 14:22
  • 1
    Some browsers may block this with a message: Navigation to toplevel data: URI not allowed (Blocked loading of: "data:text/html,<script>alert('hi');</script>") Commented Oct 22, 2019 at 16:27
  • It works on Google Chrome Version 80.0.3987.132 (Official Build) (64-bit). Commented Mar 17, 2020 at 18:01
  • 1
    Before you get too excited - this will not execute on the current page. It will load a blank document and run JS in that context. Commented Feb 2, 2024 at 12:55

lang-js

AltStyle によって変換されたページ (->オリジナル) /