Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2013, 06:49 PM   PM User | #1
colorrush
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
colorrush is an unknown quantity at this point
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
colorrush is offline   Reply With Quote
Old 02-26-2013, 04:28 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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>
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:06 AM.


Advertisement
Log in to turn off these ads.