user398341
user398341

Reputation: 6587

HTMLPurifier removes target="_blank"

I'm using HTMLPurifier and even thou I have :

$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');

it removes all 'target' attribues from the links.

Any idea why is it doing it?

Upvotes: 16

Views: 6312

Answers (2)

Bill Stoddard
Bill Stoddard

Reputation: 11

In a Yii2 application, inside of a DetailView, I configured HtmlPurifier as follows:

[
    'label' => 'Document PDF',
    'format'=> 'raw',
    'value' => HtmlPurifier::process(DocumentFunctions::viewDocumentPdfInView($model->document_id), [
    'Attr.AllowedFrameTargets' => ['_blank'],
    ]),
],

Here is a simpler way I found:

[
    'label' => 'Document PDF',
    'format'=> ['html', 'config' => ['Attr.AllowedFrameTargets' => ['_blank']]],
    'value' => DocumentFunctions::viewDocumentPdfInView($model->document_id),
]

Upvotes: 1

TuteC
TuteC

Reputation: 4382

The list of allowed frame targets is not enabled by default. You have to enable it manually.

Upvotes: 31

Related Questions