In Firefox 78, when visiting view-source:https://example.com/my-page/
, it's possible to click on any link in the HTML Source and the link will take you through to view-source:https://example.com/my-other-page/
without issue.
But if a view-source:
-prefixed link appears on a normal web page (ie. a page without a view-source:
prefix in front of the URL), the link no longer works.
This makes it impossible to add a link or a button to a page which allows the user to see the HTML Source of that page.
HTML Links are blocked:
When clicked, any link on a normal web page such as this:
<a href="view-source:https://example.com/my-page/">View Source</a>
will produce the following error in the console:
Security Error: Content at https://example.com/my-page/ may not
load or link to view-source:https://example.com/my-page/.
Javascript is blocked:
Alternatively, a <button>
which, when clicked, fires the following script:
window.open('view-source:' + window.location.href, '_blank');
will produce the following error in the console:
Uncaught Error: Access to
'view-source:https://example.com/my-page/' from script denied
Can I add a button or a link to my web page which lets me view the source of that page?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…