Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target Blank Doesn't Work #96

Open
amcdnl opened this issue May 4, 2020 · 16 comments
Open

Target Blank Doesn't Work #96

amcdnl opened this issue May 4, 2020 · 16 comments

Comments

@amcdnl
Copy link

amcdnl commented May 4, 2020

When I do:

<Linkify properties={{ target: '_blank' }}>
   {description}
 </Linkify>

and description equals:

The JSON Query expression. Reference: http://docs.jsonata.org

it will render:

The JSON Query expression. Reference: <a href="http://docs.jsonata.org">http://docs.jsonata.org</a>

with version:

"react-linkify": "^1.0.0-alpha",
@brianedelman
Copy link

Seems like it was removed in this commit from what I can tell at a quick glance 95f8607#diff-3a7bfc073d2f2d2454177d75e2f4e231

@nwesthoff
Copy link

As a workaround, you can do:

<Linkify
    componentDecorator={(decoratedHref, decoratedText, key) => (
        <a target="blank" href={decoratedHref} key={key}>
            {decoratedText}
        </a>
    )}
>

@Davinasc
Copy link

Davinasc commented Jun 2, 2020

As a workaround, you can do:

<Linkify
    componentDecorator={(decoratedHref, decoratedText, key) => (
        <a target="blank" href={decoratedHref} key={key}>
            {decoratedText}
        </a>
    )}
>

wow! works like a charm. Thank you @nwesthoff

@edi
Copy link

edi commented Jul 24, 2020

Guess this library's dead right? Wanted to use it in production due it's size, bummer.

@asp2809
Copy link

asp2809 commented Oct 6, 2020

Seems like it was removed in this commit from what I can tell at a quick glance 95f8607#diff-3a7bfc073d2f2d2454177d75e2f4e231

Seems like they have removed the support for the properties prop entirely and the only way around is using decorators as @nwesthoff suggested.

@nwesthoff
Copy link

Exactly @asp2809, that's actually how I figured out the workaround 👍

@theutkarshsoni
Copy link

@nwesthoff

I used this. But still opening in the same tab itself.
<Linkify componentDecorator={(decoratedHref, decoratedText, key) => ( <a target="blank" href={decoratedHref} key={key}> {decoratedText} </a> )} >

I checked through the inspect element. The output is following:
<a href="https://forms.gle/B8AfrGR4SE6WXd8o6">https://forms.gle/B8AfrGR4SE6WXd8o6</a>

Please help me out. I'm stuck here.

@nwesthoff
Copy link

Not sure if this is what you're running into but the Linkify component should either have a closing </Linkify> or add a / before the final > as such:

<Linkify componentDecorator={(decoratedHref, decoratedText, key) => (
    <a target="blank" href={decoratedHref} key={key}>
        {decoratedText}
    </a>)}
/>

If that doesn't help, please create a minimal reproduction on codesandbox and I might be able to help.

@theutkarshsoni
Copy link

@nwesthoff I didn't change anything but now it's working.

<Linkify componentDecorator={(decoratedHref, decoratedText, key) => ( <a target="blank" href={decoratedHref} key={key}> {decoratedText} </a> )} >

Thanks @nwesthoff

@dbudwin
Copy link

dbudwin commented Dec 26, 2020

You can create a decorator like some of the other comments here have mentioned. If you want to open new tabs securely, especially if the links are leaving the site you control, I suggest implementing the following:

TypeScript supported CodeSandbox: https://codesandbox.io/s/cool-montalcini-vkmtb?file=/src/App.tsx

npm install react-secure-link

...then...

import { SecureLink } from "react-secure-link"

<Linkify componentDecorator={(decoratedHref, decoratedText, key) => (
    <SecureLink href={decoratedHref} key={key}>{decoratedText}</SecureLink>
)}>
    Here is a link that will open securely in a new tab: www.github.com.
</Linkify>

@ryanbuckleyca
Copy link

ryanbuckleyca commented Sep 14, 2021

nice. thank you @nwesthoff, as the docs still show the properties prop: http://tasti.github.io/react-linkify/

@ahAskari
Copy link

You can create a decorator like some of the other comments here have mentioned. If you want to open new tabs securely, especially if the links are leaving the site you control, I suggest implementing the following:

TypeScript supported CodeSandbox: https://codesandbox.io/s/cool-montalcini-vkmtb?file=/src/App.tsx

npm install react-secure-link

...then...

import { SecureLink } from "react-secure-link"

<Linkify componentDecorator={(decoratedHref, decoratedText, key) => (
    <SecureLink href={decoratedHref} key={key}>{decoratedText}</SecureLink>
)}>
    Here is a link that will open securely in a new tab: www.github.com.
</Linkify>

Thanks, this worked for me

@Ponao
Copy link

Ponao commented Jul 5, 2022

Вы можете создать декоратор, как упоминалось в некоторых других комментариях. Если вы хотите безопасно открывать новые вкладки, особенно если ссылки уходят с контролируемого вами сайта, я предлагаю реализовать следующее:

CodeSandbox с поддержкой TypeScript: https://codesandbox.io/s/cool-montalcini-vkmtb?file=/src/App.tsx

npm install react-secure-link

...тогда...

import { SecureLink } from "react-secure-link"

<Linkify componentDecorator={(decoratedHref, decoratedText, key) => (
    <SecureLink href={decoratedHref} key={key}>{decoratedText}</SecureLink>
)}>
    Here is a link that will open securely in a new tab: www.github.com.
</Linkify>

I think we dont need install package for this goal, we can just add rel="noopener noreferrer". Just a thought

@pvbgsharma-wal
Copy link

<Linkify options={{target:'blank'}}> {data} </Linkify>
this is helpful and working fine

@durgeshm01722
Copy link

durgeshm01722 commented Jun 9, 2023

In the current version i.e. "^1.0.0-alpha", the support for properties is removed. You can either do like this:

<Linkify
    componentDecorator={(decoratedHref, decoratedText, key) => (
        <a target="blank" href={decoratedHref} key={key}>
            {decoratedText}
        </a>
    )}
>

Else, downgrade to version "0.2.2". Worked for me!

Repository owner deleted a comment from Nitesh639 Feb 26, 2024
@kylegillen
Copy link

I assume this should be closed. This worked fine for me on version 4.1.3: #96 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests