CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   XML (http://www.codingforums.com/forumdisplay.php?f=3)
-   -   Open link in new window (http://www.codingforums.com/showthread.php?t=288269)

colorrush 02-25-2013 06:49 PM

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 :)

sunfighter 02-26-2013 04:28 PM

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>



All times are GMT +1. The time now is 11:10 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.