How do i stop my search bar from opening a new tab?

≯℡__Kan透↙ 提交于 2019-12-25 02:18:20

问题


How do i stop my search bar from opening a new tab? I dont see whats making it do that? Heres my php code. I've been having a couple issues with this search bar recently...

Heres my code (It is very very long...):

 <?php
    $xmlDoc=new DOMDocument();
    $xmlDoc->load("links.xml");

    $x=$xmlDoc->getElementsByTagName('link');

    //get the q parameter from URL
    $q=$_GET["q"];

    //lookup all links from the xml file if length of q>0
    if (strlen($q)>0)
    {
    $hint="";
    for($i=0; $i<($x->length); $i++)
      {
      $y=$x->item($i)->getElementsByTagName('title');
      $z=$x->item($i)->getElementsByTagName('url');
      if ($y->item(0)->nodeType==1)
        {
        //find a link matching the search text
        if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
          {
          if ($hint=="")
            {
            $hint="<a href='" . 
            $z->item(0)->childNodes->item(0)->nodeValue . 
            "' target='_blank'>" . 
            $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
            }
          else
            {
            $hint=$hint . "<br /><a href='" . 
            $z->item(0)->childNodes->item(0)->nodeValue . 
            "' target='_blank'>" . 
            $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
            }
          }
        }
      }
    }

    // Set output to "No suggestions" if no hint were found
    // or to the correct values
    if ($hint=="")
      {
      $response="No suggestion";
      }
    else
      {
      $response=$hint;
      }

    //output the response
    echo $response;
    ?>

回答1:


you need to remove remove target='_blank'




回答2:


Replace this

$z->item(0)->childNodes->item(0)->nodeValue . 
            "' target='_blank'>" .

by this

$z->item(0)->childNodes->item(0)->nodeValue . 
            "'>" .

tag target="_blank" make opening link in new window



来源:https://stackoverflow.com/questions/22584204/how-do-i-stop-my-search-bar-from-opening-a-new-tab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!