如何在新窗口中打开MAILTO链接(PHP echo)?
代码:
<?php
global $listing_id;
$listing_id = ( is_null( $listing_id ) ) ? get_the_ID() : $listing_id;
$user_added_by = get_post_meta( $listing_id, 'stm_car_user', true );
$user_fields = stm_get_user_custom_fields( $user_added_by );
?>
<div class="dealer-contact-unit mail">
<a href="mailto:<?php echo esc_attr( $user_fields['email'] ); ?>">
<div class="email-btn heading-font">
<?php echo wp_kses( $de_icon, apply_filters( 'stm_ew_kses_svg', array() ) ); ?>
<span>
<?php echo esc_html( $de_label ); ?>
</span>
</div>
</a>
</div>
我的尝试。排队:
<a href="mailto:<?php echo esc_attr( $user_fields['email'] ); ?>">
我将 target="_blank" 如下:
<a href="mailto:<?php echo esc_attr( $user_fields['email'] ); ?>" target="_blank">
或喜欢:
<a target="_blank" href="mailto:<?php echo esc_attr( $user_fields['email'] ); ?>">
但是在这两种情况下都不会打开新选项卡。
有人可以帮助我吗?
试试这个
document.addEventListener('DOMContentLoaded',() => {
document.querySelector('.mail').addEventListener('click',(e) => {
const email = e.target.closest('div.dealer-contact-unit mail').dataset.href;
window.open(email,'_blank');
// or
// location.href=email;
});
});
<div class="dealer-contact-unit mail" data-href="mailto:<?php echo esc_attr( $user_fields['email'] ); ?>">
<div class="email-btn heading-font">
<?php echo wp_kses( $de_icon, apply_filters( 'stm_ew_kses_svg', array() ) ); ?>
<span>
<?php echo esc_html( $de_label ); ?>
</span>
</div>
</div>