html 目标属性并非在所有方案中都有效

gk7wooem  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(167)

Problem

I have tried to make a link on a pop-up user registration form open in a new browser tab, but it seems to ignore any targeting script added and keep opening the link the same tab.

Additional context:

  • The site is based on a Wordpress template
  • " " works fine in other area of the site
<div class="form-group">
    <label for="register-terms-and-conditions">
        <input type="checkbox" name="terms_and_conditions" value="on" id="register-terms-and-conditions" oninvalid="setCustomValidity('Please accept the terms and conditions before proceeding')" oninput="setCustomValidity('')" required>
        <?php
            echo sprintf(wp_kses(__('I accept the <a href="https://www.google.com" target="_blank" >terms and conditions*</a>'), array('a' => array('href' => array())) ), esc_url($page_url));
                ?>
    </label>
</div>

What I have tried

  1. I checked the browsers' behavior and tested with Chrome, Safari, Firefox. The results did not change.
  2. I tried testing other <a target= attributes ("blank", "_parent", "_top" to see if it is simply the problem with triggering the new tab. The results did not change.
  3. Tried onclick=" ". The result did not change.
echo sprintf(wp_kses(__('I accept the <a onclick="window.open(this.href,'_blank');return false;" href="https://www.google.com" >terms and conditions*</a>'), array('a' => array('href' => array())) ), esc_url($page_url));

uemypmqf

uemypmqf1#

收到替换echo的建议。target="_blank”现在工作正常

<div class="form-group">
    <label for="register-terms-and-conditions">
        <input type="checkbox" name="terms_and_conditions" value="on" id="register-terms-and-conditions" required="">
            Accept <a href="https://google.com" target="_blank">Terms and Conditions*</a>
        ?>
    </label>
</div>

相关问题