# \[Space-Script\] Add URL to Page (Web Bookmark List)

**URL:** https://community.silverbullet.md/t/space-script-add-url-to-page-web-bookmark-list/1666
**Category:** Tricks & Techniques
**Created:** [January 19, 2025, 10:59am UTC](https://community.silverbullet.md/t/space-script-add-url-to-page-web-bookmark-list/1666 "2025-01-19T10:59:26Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![CaffeineFueled](https://community.silverbullet.md/user_avatar/community.silverbullet.md/caffeinefueled/32/802_2.png) [@CaffeineFueled](https://community.silverbullet.md/u/CaffeineFueled)
#### Post date: [January 21, 2025, 12:23pm UTC](https://community.silverbullet.md/t/space-script-add-url-to-page-web-bookmark-list/1666/4 "2025-01-21T12:23:38Z")

</div>

This should do the trick

```js
silverbullet.registerCommand(
  { name: "Add Web Bookmark" },
  async () => {
    // Prompt the user for the URL
    const url = await editor.prompt("Enter the URL:");
    if (!url) {
      await editor.flashNotification("No URL provided.", "error");
      return;
    }

    // Retrieve the current page name
    const currentPageName = await editor.getCurrentPage();

    // Prompt the user for the page name, with the current page name as the default value
    const pageName = await editor.prompt(
      "Enter the page name to insert the URL into:",
      "" // Suggest the current page name as the default value
    ) || currentPageName; // Fallback to the current page if input is empty

    try {
      // Read the page content, or initialize it if the page does not exist
      let pageContent;
      try {
        pageContent = await space.readPage(pageName);
      } catch (e) {
        // Assume the page does not exist, initialize with empty content
        pageContent = "";
      }

      // Append the URL as plain text
      const updatedContent = `${pageContent}\n${url}`;

      // Write the updated content back to the page
      await space.writePage(pageName, updatedContent);
      await editor.flashNotification(`URL successfully inserted into ${pageName}.`);
    } catch (error) {
      console.error("Error while inserting URL:", error);
      await editor.flashNotification("An error occurred while inserting the URL.", "error");
    }
  }
);

```

---

_[View the full topic](https://community.silverbullet.md/t/space-script-add-url-to-page-web-bookmark-list/1666)._
