MyBB Community Forums

Full Version: Is there a way of linking within a post (anchor?)?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Just suddenly had a thought about this and wondered if there was a way of linking to a section within a post (something like HTML anchor tags?) with MyBB?

Apologies if this is already documented - I wasn't sure what search phrase I should be using.

Thanks Smile
Nope, it could be done with MyCode though Smile
Thanks Paul! Smile I shall have a look into it!

Do you think its a feature that might be introduced for the main MyBB forums?
(2011-12-06, 10:26 PM)Paul H. Wrote: [ -> ]Nope, it could be done with MyCode though Smile

Hey, do you mind explaining how to do this?

Also, I'm quite shocked that even after all this time (ie, since this old thread), I still can't find any info on such markup.
Try creating a MyCode like this: (not tested)

Regular Expression:
\[section\]([a-zA-Z0-9]+)\[/section\]

Replacement:
<a name="$1"></a>
It partially works. Clicking a URL with link.com#anchor will result in a new tab opening, and the page loading, but it does jump to the right area. Can I get it to just jump to the right section on the same tab without loading the page again?

I think I need to create a MyCode for the link as well, but how can I introduce a URL variable so that the replacement becomes something along the lines of <a href="*URL of current page*#anchor">*URL label*</a>?
(2013-04-01, 04:25 AM)hiig Wrote: [ -> ]It partially works. Clicking a URL with link.com#anchor will result in a new tab opening, and the page loading, but it does jump to the right area. Can I get it to just jump to the right section on the same tab without loading the page again?
Not exactly sure what you're trying to say here... does it work, or what doesn't work? Example link or post?

(2013-04-01, 04:25 AM)hiig Wrote: [ -> ]I think I need to create a MyCode for the link as well, but how can I introduce a URL variable so that the replacement becomes something along the lines of <a href="*URL of current page*#anchor">*URL label*</a>?

Maybe...
\[urla\=([a-zA-Z0-9]+)\](.*?)\[/urla\]
<a href="#$1">$2</a>
(2013-04-01, 06:32 AM)April Fool Wrote: [ -> ]does it work, or what doesn't work?

Normally when you click a link, it opens in a new tab. The target attribute is _blank. This same attribute is being applied in these links, so even though the link is to an anchor on the same page, a new tab is still opened, whereas it should be _self.

Anyway, I ended up using your suggestion, and adding that bit, so I have the following:

\[anchorlink\=([a-zA-Z0-9]+)\](.*?)\[/anchorlink\]

<a href="#$1" target="_self">$2</a>

...but it didn't work. The post just shows it exactly as I typed it with the attempted markup.

One thing I'm confused about...In the HTML, you have the variables defined as $n, with n representing a different variable, yes? How is it supposed to know which variable is which in the markup form?
Do you have a link to the post you tried it in?
Not really. It's a private forum.
Pages: 1 2