how do i make a link open a new tab?

Frak_Lou_Elmo
Frak_Lou_Elmo
edited March 5 in Campaign Portal Building

Sorry if this seems like a noob question that can be easily googled, but I cant get it to work.

 

I have some links at the bottom of my front page: https://gaximplague.obsidianportal.com/

For example the one that goes to Owlbear Rodeo, it was:

<a href="https://www.owlbear.rodeo/game/vfJl78b3I">[[File:1151463  | class=media-item-align-center | 200x200px | Owlbear Rodeo]]</a>"Whiteboard for battles":https://www.owlbear.rodeo/game/vfJl78b3I

Then I changed it to:

<a href="https://www.owlbear.rodeo/game/vfJl78b3I"; target="_blank">[[File:1151463  | class=media-item-align-center | 200x200px | Owlbear Rodeo]]</a>"Whiteboard for battles":https://www.owlbear.rodeo/game/vfJl78b3I</td>;

(edit: ignore the ; I see appearing here before the word 'target', i don't know why it appears after i post this comment as I certainly didnt type it) 

I thought the target="_blank" would do the trick but it is still opening in the same tab. what am I doing wrong?

Post edited by Frak_Lou_Elmo on



twitter: @Frak_Lou_Elmo

Comments

  • thaen
    thaen
    Posts: 943

    You're not doing anything wrong.  That would be exactly the way to do this ... if there wasn't a catch.  : )  The "_blank" target can be used to hack a visitor's computer, so OP removes it from the generated HTML after you click Save.  If you "inspect" the link that you've created, you'll see that the "target" attribute isn't there.

    But, we've got a new beta feature of Custom JavaScript that can make this work.  So, you could do this through a "class".  You would tag the url with a class of "target_blank" (for example).  Then you would add Custom JavaScript code of like this:


    $('.target_blank').attr("target", "_blank");

    Then any url in your campaign that had the "target_blank" class would be automatically given the "target=_blank" attribute ... and would open in a new window when the visitor clicked it.

    Obsidian Portal Developer

  • thaen
    thaen
    Posts: 943

    @Frak_Lou_Elmo, I just added you to the Custom JavaScript beta feature, so you can try this out now if you like.

    Obsidian Portal Developer

  • Frak_Lou_Elmo
    Frak_Lou_Elmo
    Posts: 170

    oh wow, thank you! I had to look this up and found out about "tabnapping", I guess that is what we are talking about here. I will try out your solution.



    In the source I read about tabnapping, it advised adding rel="noopener noreferrer" after target_"blank" to prevent this security breach. Wouldn't that help and bypass the need for custom javascript?



    twitter: @Frak_Lou_Elmo

  • thaen
    thaen
    Posts: 943

    Yes, it looks like adding noopener could fix this for most browsers. 

    https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/noopener

    Actually it looks like most browsers  now implicitly add noopener for target _blank links ... though Opera is still a notable holdout according to this chart:

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#browser_compatibility

    I'll add "adding noopener" to the "todo list".  Thanks!

    Obsidian Portal Developer

Sign In or Register to comment.

July 2022
Signs and Portends

Read the feature post on the blog
Return to Obsidian Portal

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Discussions