Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open link in new window

    Hi!

    I have some trouble getting af link to open in a new window.

    Tak a look at the code in the XML file: http://i.imgur.com/Q3gnLOk.jpg

    I want the third link (facebook) to open in a new window. How can I do this?

    Thanks in advance

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    This is just an example. I only did it for firefox and it depends on only having three entrees in xml. I hope you know how to read an xml and get the right url:
    The XML:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <links>
    
    <link category="COOKING">
      <url>goole</url>
      <img>2005</img>
    </link>
    
    <link category="CHILDREN">
      <url>google</url>
      <img>2005</img>
      <price>29.99</price>
    </link>
    
    <link category="WEB">
      <url>http://facebook.com/</url>
      <img>2003</img>
    </link>
    
    </links>
    The Javascript:
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <script>
    function loadXMLDoc(dname)
    {
    if (window.XMLHttpRequest)
      {
      xhttp=new XMLHttpRequest();
      }
    else
      {
      xhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xhttp.open("GET",dname,false);
    xhttp.send("");
    return xhttp.responseXML;
    }
    
    xml=loadXMLDoc("Links.xml");
    path="/links/link/url"
    // code for IE
    if (window.ActiveXObject)
    {
    var nodes=xml.selectNodes(path);
    
    for (i=0;i<nodes.length;i++)
      {
      document.write(nodes[i].childNodes[0].nodeValue);
      document.write("<br>");
      }
    }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument)
    {
    var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
    var result=nodes.iterateNext();
    
    while (result)
      {
      jimmy = result.childNodes[0].nodeValue;
      document.write(result.childNodes[0].nodeValue);
      document.write("<br>");
      result=nodes.iterateNext();
      }
    }
    /*bill = String(jimmy);   <= YOU MIGHT HAVE TO DO THIS, DON'T KNOW*/
    window.open(jimmy);
    </script>
    
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •