Links to different page parts

Hello,

Does anybody know if it’s possible (and if so, how) to link different parts of the same page (at different scrolls).

Best,

Hi @GDB! This is possible with good ol’ HTML. If you want to use sub-headers for example, you can use the id attribute. Here’s an example post where I link to a second header section in the post: https://write.as/cvf2jay8xzqp9q75.md#second

To accomplish this, I simply wrote out the subheader with HTML and put in the ID — something short that makes sense.

<h2 id="second">Second Header</h2>

Then all you have to do is link to it by taking your post’s link and adding a hash with the id’s name. So in the above’s case, #second. This creates the general link: https://write.as/cvf2jay8xzqp9q75.md#second

Doing this with Markdown is extended syntax that we’d definitely look into if there was demand.

Hope that makes sense and helps! Would be glad to clarify further if need be.

Count me in as someone who would want to do this via Markdown. I have also done it using html and ids, but it would be great to be able to handle it with Markdown.

Hey,

This is Gdb, thanks for your response.

What if I was looking for a solution that did not involve a header?

Best,

So what did you have in mind @GDB? All you need to do is add the id to whatever HTML element in your post you had in mind to link to & use the hash in the url as referenced above.

I think I understand the concept.

Thank you!

1 Like

The problem I’m having is that I need to create navigation links to other header sections within the same page, but when I click on them it opens a new page tab (navigating to the specified header) rather than navigating to that header within the same page. Thus I get a proliferation of open tab pages whereas I want to stay within the same page.

Creating links to other sections of the same page should work according to various references, such as this one. But it appears that something is happening in write.as such that a new page is opened rather than navigating to the link within the same page.

I’ve tried specifying target="_parent" and target="_self", but that doesn’t work.

Does anyone know how to get this to work?

Ah got it — how about something like this?

<a href="#second"><h2 id="second">Blah Blah Blah</h2></a>

I have a demo here where, if you click the link on the first line, it will go to that part in the post without opening a new page tab. Let me know if that works @bugbuster!

Thanks cj, but it didn’t work in a write.as blog post. Here’s the very strange thing - it works in an anonymous post just as you described, but does not work in a blog post."

Something appears to be different in blog posts vs anonymous. Any ideas?

@cjeller1592 Another strange thing - It appears to be exclusively a write.as blog post thing. I tried it in blog posts on two different WriteFreely instances and it worked perfectly in both.

Thanks for keying in on where it’s happening @bugbuster — that helps a lot actually! There might be something different with the Write.as codebase that is causing this to happen. We’ll look into it and I’ll keep you posted (unless @matt jumps in).

1 Like

Reporting back on the solution I just found. The origin of the problem was that I entered some really nice custom Javascript code from this forum post, as a privacy and security measure: Add rel =“noreferrer noopener” to external links by default as a privacy & security measure

It included this line of code, which will open all links in a new tab:
//post_links[i].target = "_blank";

So I modified the code to execute that line ONLY for links external to write.as/writeas.com. Now links to internal parts of a blog page work fine (staying within the page) while still having protection when navigating to external sites (which continue to open in a new page).

h = post_links[i].href;
if (!h.includes("write.as") && !h.includes("writeas.com") {
  post_links[i].target = "_blank";
}
1 Like