+ Start a Discussion
Winsoft Tech.Winsoft Tech. 

problem for Parsing XML Data from URL in custom s-control

Hello:
 
In Custom s-control , i want to read xml data from follwing URL.
 
And want to display the parsed xml data in a table using Html and javascript.
 
But when I load this xml file using  custom s-control:
 
var myxmldoc=new ActiveXObject("Msxml2.DOMDocument");
It is giving me error that Access is denied. Below is the source code.
 
 
 
 
Code:
<html>
<head>
 <title>TurboWidgets Example - TurboGrid</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
  
 <script language="JavaScript" type="text/javascript"> 
  function StockUrl()
 {
  alert("In StockUrl()");
  var ReadText=document.getElementById("names");
  var url="http://www.411sync.com/cgi-bin/search.rss—kw=quote" + " "+ ReadText.value;
  alert(url);
  Navigate(url);

 }
 function Navigate(url)
 {
  alert("In Navigate");
  var row;
  var x;
  var y;
  var z;
  var myxmldoc=new ActiveXObject("Msxml2.DOMDocument");
  var i;
  alert(1);
  myxmldoc.async=false;
  alert(2);
  alert(url);
  myxmldoc.load(url);
  alert(3);
  var temp="";  
  var root=myxmldoc.documentElement;
  alert("root.getElementsByTagName('item').length");   
  for(i=0;i<root.getElementsByTagName('item').length;++i)
  { 
   temp += root.getElementsByTagName("item/title")[i].childNodes[0].nodeValue + " ";
   alert(temp);
  }
  alert(4);
  var temp1 = temp.split(" ");
  var arr=[temp1.length-1];
  for (var j=0;j<temp1.length-1;j++)
  { 
   arr[j]=temp1[j];
   
  }
  var count=0;   
   for (i=0;i<(temp1.length-1)/3;i++)
   {
   row=document.getElementById("output").insertRow(i+1);
   for (var j=0;j<3;j++)
   {
       
    var y=row.insertCell(j);
    y.innerHTML=arr[count++];
    }
   
  }
  
 }

 </script>
 </head>
<body>  
 <input type="text" id="names" name="names" />
 <input type="button" id="GetStock" name="GetStock" onclick="StockUrl()" value="Get" />
 
 <table border="1" id="output">
 <tr>
  <td>Stock</td>
  <td>Market rate</td>
  <td>Change</td>
 </tr>
 </table>

</body>
</html>

 
Its working properly if i make a simple html file of that code and run from my system.(Not on salesforce.com).
 
But when i use same code in s-control on salesforce.com ,  i am facing this problem (Access is denied while loading XML data through URL)
 
Note:
In this code, there is a textbox which allow user to enter names of the scrips e.g  Goog, Yhoo etc.
On click of button Get , Only data for entered text is parsed from mentioned URL and displays in a table.

 
Whether  anybody is having solution of mentioned problem?
 
 
Ron HessRon Hess
this is cross-domain scripting and prohibited by browser security.

one possible solution,
you can create an <iframe element in your code, and reach out to other domains from code within that iframe i believe.

see the Yelp mashup on AppExchange for an example of how this can be done.