【问题标题】:What code do I need to add to open in a new window?我需要添加什么代码才能在新窗口中打开?
【发布时间】:2012-04-23 18:20:00
【问题描述】:

我有一个价格表插件,可以在同一窗口中打开按钮链接。我想在一个新的空白窗口中打开主题。我需要在这个文件中添加什么代码?

另请注意,链接是由 wordpress 插件生成的,因此我无法在代码中手动添加 target="_blank"。

感谢您的帮助

<div class="price-columns">
    <div id="column-skeleton" style="display:none">

        <span class="ui-icon ui-icon-carat-2-e-w column-handle"></span>
        <a href="#" class="ui-icon ui-icon-trash submitdelete deletion"></a>

        <div class="type">
            <input type="radio" value="recommend" name="price_recommend" />
            <label><?php _e('Recommend', 'pricetable') ?></label>
        </div>

        <input type="text" class="column-title" name="" placeholder="<?php _e('Title', 'pricetable') ?>" />
        <input type="text" class="column-price" name="" placeholder="<?php _e('Price', 'pricetable') ?>" />
        <input type="text" class="column-detail" name="" placeholder="<?php _e('Detail', 'pricetable') ?>" />
        <input type="text" class="column-url" name="" placeholder="<?php _e('Button URL', 'pricetable') ?>" />
        <input type="text" class="column-button" name="" placeholder="<?php _e('Button Text', 'pricetable') ?>" />

        <h4><a href="#" class="addfeature"><?php _e('Add', 'pricetable') ?></a><?php _e('Features', 'pricetable') ?></h4>
        <div class="feautres">
            <div class="feature">
                <span class="ui-icon ui-icon-carat-2-n-s feature-handle"></span>
                <a href="#" class="ui-icon ui-icon-trash submitdelete deletion"></a>

                <div><input type="text" class="feature-title" placeholder="<?php _e('Title', 'pricetable') ?>"/></div>
                <div><input type="text" class="feature-sub" placeholder="<?php _e('Sub title', 'pricetable') ?>" /></div>
            </div>
        </div>
    </div>

    <?php // Existing columns of the price table ?>
    <?php foreach($table as $i => $column) : ?>
        <div class="column">
            <span class="ui-icon ui-icon-carat-2-e-w column-handle"></span>
            <a href="#" class="ui-icon ui-icon-trash submitdelete deletion"></a>

            <div class="type">
                <input type="radio" name="price_recommend" id="price_recommend_<?php print $i ?>" value="<?php print $i ?>" <?php if(isset($column['featured']) && $column['featured'] === 'true') print 'checked="true"'; ?> />
                <label for="price_recommend_<?php print $i ?>"><?php _e('Recommend', 'pricetable') ?></label>
            </div>

            <input type="text" class="column-title" name="price_<?php print $i ?>_title" value="<?php @esc_attr_e($column['title']) ?>" placeholder="<?php _e('Title', 'pricetable') ?>" />
            <input type="text" class="column-price" name="price_<?php print $i ?>_price" value="<?php @esc_attr_e($column['price']) ?>" placeholder="<?php _e('Price', 'pricetable') ?>" />
            <input type="text" class="column-detail" name="price_<?php print $i ?>_detail" value="<?php @esc_attr_e($column['detail']) ?>" placeholder="<?php _e('Detail', 'pricetable') ?>" />
            <input type="text" class="column-url" name="price_<?php print $i ?>_url" value="<?php @esc_attr_e($column['url']) ?>" placeholder="<?php _e('Button URL', 'pricetable') ?>" />
            <input type="text" class="column-button" name="price_<?php print $i ?>_button" value="<?php @esc_attr_e($column['button']) ?>" placeholder="<?php _e('Button Text', 'pricetable') ?>" />

            <h4><a href="#" class="addfeature"><?php _e('Add', 'pricetable') ?></a><?php _e('Features', 'pricetable') ?></h4>
            <div class="feautres">
                <?php if(isset($column['features'])) : foreach($column['features'] as $j => $feature) : ?>
                    <div class="feature">
                        <span class="ui-icon ui-icon-carat-2-n-s feature-handle"></span>
                        <a href="#" class="ui-icon ui-icon-trash submitdelete deletion"></a>

                        <div><input type="text" class="feature-title" name="price_<?php print $i ?>_feature_<?php print $j ?>_title" value="<?php esc_attr_e($feature['title']) ?>" placeholder="<?php _e('Title', 'pricetable') ?>"/></div>
                        <div><input type="text" class="feature-sub" name="price_<?php print $i ?>_feature_<?php print $j ?>_sub" value="<?php esc_attr_e($feature['sub']) ?>" placeholder="<?php _e('Sub title', 'pricetable') ?>" /></div>
                    </div>
                <?php endforeach; endif; ?>
            </div>
        </div>
    <?php endforeach ?>

    <div class="column addnew"><?php _e('Add Column', 'pricetable') ?></div>
    <div class="clear"></div>
</div>

【问题讨论】:

  • 如果你想让它在一个单独的窗口中,为什么不包含这个页面的链接=> target="_blank"
  • 好的,每次 a href= 我都输入了 target="_blank" 但没有运气。这个按钮在哪里呈现? url 是从在 wordpress 插件后端输入的自定义 url 呈现的。
  • @gopi1410 我知道目标“_blanc”,但是因为这不起作用,我想让我们在这里问这个问题,因为像你们这样的程序员应该很容易回答;-)
  • @Justmac:刚刚添加了一个答案,检查一下。它应该可以工作。

标签: php html


【解决方案1】:

您可以在&lt;a&gt; 标签中使用target="_blank"

【讨论】:

  • 请不要用 w3school 链接污染我的答案。请参阅 w3fools.comMDN 以获得正确的参考。
  • 哈哈。不知道 w3schools 被这么讨厌。我删除了链接:)
【解决方案2】:

好的,如果您的链接是由 wordpress 生成的,您可以考虑在页面加载后动态添加目标属性。 Use the following script after page load or document ready:

<head>
<script type="text/javascript">

function add_target()
{
   // Find all the anchors you want to modify
   var anchors = document..getElementsByTagName('a'),
   i = anchors.length;

   // Add the target to each one
   while(i--) anchors[i].target = "_blank";
}

</script>
</head>

<body onload="add_target()">
/* your body */
</body>

【讨论】:

  • 感谢您的帮助,我真的很感激,但我觉得自己像个菜鸟,因为我不知道在哪里添加它。我认为这是添加到文件中的简单代码行,但我想我会聘请我的程序员来解决这个问题 :-) 再次感谢您的帮助 ;-)
  • 我以为这条线与它有关,但我想我错了。
  • 更新了代码,只是将
  • 不,输入类型与链接无关。
【解决方案3】:

添加到每个 目标="_blank" 就是这样。

【讨论】:

    【解决方案4】:

    在您的代码中使用&lt;a href="your_url" target="_blank"&gt;link&lt;/a&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多