Skip to Content

Solved: What is about:blank or javascript: URL referring in Same-origin-policy?

Question

I am learning about the Same-origin-policy of web security stated in MDN Web Docs regarding the scripts executed from pages with an about:blank or javascript: URL inherit the origin of the document containing that URL. I not really understand how does the javascript: URL referring to and I couldn’t find any other related description or example regarding javascript: URL.

Answer

Same-origin-policy of web security stated in MDN Web Docs is talking about the javascript:, pseudo-protocol, or URI scheme which is where you place one or more javascript statements as the value of an HTML attribute whose value is a URL (URI).

Here’s a basic example: <a href="javascript:alert('hello world')">click me</a>

Use of the javascript: pseudo-protocol in production web sites is not good practice. However, it’s quite useful for bookmarklets which are short user-scripts that can be stored as bookmarks in your browser to do automated things to the page in your current browser tab.

Alex Lim is a certified IT Technical Support Architect with over 15 years of experience in designing, implementing, and troubleshooting complex IT systems and networks. He has worked for leading IT companies, such as Microsoft, IBM, and Cisco, providing technical support and solutions to clients across various industries and sectors. Alex has a bachelor’s degree in computer science from the National University of Singapore and a master’s degree in information security from the Massachusetts Institute of Technology. He is also the author of several best-selling books on IT technical support, such as The IT Technical Support Handbook and Troubleshooting IT Systems and Networks. Alex lives in Bandar, Johore, Malaysia with his wife and two chilrdren. You can reach him at [email protected] or follow him on Website | Twitter | Facebook

    Ads Blocker Image Powered by Code Help Pro

    Your Support Matters...

    We run an independent site that is committed to delivering valuable content, but it comes with its challenges. Many of our readers use ad blockers, causing our advertising revenue to decline. Unlike some websites, we have not implemented paywalls to restrict access. Your support can make a significant difference. If you find this website useful and choose to support us, it would greatly secure our future. We appreciate your help. If you are currently using an ad blocker, please consider disabling it for our site. Thank you for your understanding and support.