简体   繁体   中英

HTML link starting with “vscode:” to open a file in Visual Studio Code

According to issue #4883 and PR #15320 you can create vscode:/ links in your HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>

<h1>Test</h1>
<a href="vscode://path/to/my/file.md">open file.md in vscode</a> 

</body>
</html> 

This should have the same effect than typing following in the console:

code -g -r /path/to/my/file.md

But what I get is different:

示例页面

After click:

单击后的示例页面

And after clicking on "Open Visual Studio Code", then the application is opened (or put in the foreground) but the file is not opened.

What did I miss?

I have tried <a href="vscode:///path/to/my/file.md"> but the result is the same.

I found the solution in this answer : you need a file/ prefix before the path of your file:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>

<h1>Test</h1>
<a href="vscode://file/path/to/my/file.md">open file.md in vscode</a> 

</body>
</html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM