View Full Version : Looking for Java Script Help
razorbax
07-23-2009, 08:50 PM
HI Everyone,
I am trying to write an Achievments Widget for Blogger that lists the 5 most recent achievments. I have come up with the code below. It works perfectly as a stand alone web page, but does not work as a HTML/Java Widget. Any advice would be greatly appreciated.
<script type="text/javascript">
var xmlDoc;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}if (xmlDoc!==null)
{
xmlDoc.async=false;
xmlDoc.load("http://www.wowarmory.com/character-achievements.xml?r=Nagrand&cn=Razorbaxftw");
for (i=0;i<xmlDoc.getElementsByTagName('achievement').length; i++)
{
x=xmlDoc.getElementsByTagName("achievement")[i].attributes;
y="http://www.wowhead.com/?achievement=";
document.write("" + x.getNamedItem("title").nodeValue + " ( + y +x.getNamedItem()
");
}
}
</script>
The Error in FF is Message:
"Unterminated string constant
Line: 726
Char: 59
Code: 0
URI: http://tdntesting.blogspot.com/"
and it is refering to:
document.write("" + x.getNamedItem("title").nodeValue + " ( + y +x.getNamedItem()
");
Svpernova09
07-24-2009, 10:02 AM
Some good info here, not really using javacript, but some perl and php references you may be able to get some info out of.
http://elitistjerks.com/f15/t14035-how_get_xml_php_armory/
not sure what your issue is, but looking at your <A> tag, wouldn't you want to have quotes around the href param?
sorta like : (in red - not easy to see)
document.write("<a href='" + y +x.getNamedItem("id").nodeValue + "'>" + x.getNamedItem("title").nodeValue + "</a>
");
Rakhman
07-25-2009, 02:30 PM
I think the problem here is blogger. When I paste your code into my own HTML/JavaScript widget, save and re edit it I see:
document.write("" + x.getNamedItem("title").nodeValue + " ( + y +x.getNamedItem()
");
It looks like blogger has somehow corrupted the contents of the script. I have figured out that you need a space in the for loop:
for (i=0; i < xmlDoc.getElementsByTagName('achievement').length; i++)
If you put
for (i=0; i <xmlDoc.getElementsByTagName('achievement').length; i++)
I think the silly editor thinks <xmlDoc is some sort of html tag and gets all confused. So something similar might be happening with the document.write line, I haven't had time to look into it more.
Basically I suggest raiding a help ticket against Blogger saying their HTML editor is silly and is messing up your Javascript!
razorbax
07-28-2009, 07:28 PM
THanks for all the sugestions. I got past that error but I think I have hit the roadblock.
I broke up the document.write so it was multiple lines and blogger no longer breaks it.
document.write("<");
document.write("a");
document.write(" ");
document.write("href=");
document.write(y);
document.write(x.getNamedItem("id").nodeValue);
document.write(">");
document.write(x.getNamedItem("title").nodeValue);
document.write("</a>
");
Now the issue is I get an "Access Denied" error. In Firebug it appears as follows.
Error: uncaught exception: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "http://tdntesting.blogspot.com/ Line: 722"]
I think its just a cross domain permission error that I can not get past. If anyone knows a workaround, please let me know.
Thanks again for all the help
Dorffo
07-30-2009, 06:53 PM
You're running into cross domain issues- do you have access to a server-side language (PHP/ASP/RoR etc)?
If so I can probably PM you the code to get around the issue.
You need the domain that serves your page to serve the data rather than requesting it from the remote domain via javascript - so what you'll want to do is grab the data on page-load, or cache it somewhere on your domain and then reference that with your JavaScript block.
razorbax
07-30-2009, 07:18 PM
You're running into cross domain issues- do you have access to a server-side language (PHP/ASP/RoR etc)?
If so I can probably PM you the code to get around the issue.
You need the domain that serves your page to serve the data rather than requesting it from the remote domain via javascript - so what you'll want to do is grab the data on page-load, or cache it somewhere on your domain and then reference that with your JavaScript block.
I am not sure what defines the domain. Basically I have a blogger blog and my domain name forwards to it.
Original Domain is http://threedruidnoob.blogspot.com and my domain is http://www.threedruidnoob.com
So I am assuming the domain would be blogger.com. So I do not think I have access to any server side languages. It is done thorough google aps though so maybe I do have some of that functionallity just I dont know about it.....
Dorffo
07-31-2009, 01:51 PM
I'm pretty sure there's a way around it - but after goofing around with a test blogger account last night I couldn't come up with any quick methods that don't require a 3rd host for the proxy files :(
Hey I followed the link of threedruidnoob's blog to this post because I'm trying to solve the same problem; getting a nice achievement feed on my blog.
I kind of have something working, but it's a hack- I'm just regex shredding the achievements off of the rendered HTML page. I think the most elegant solution would be to get a Yahoo! Pipe to Fetch the XML file and then render the relevant xml items as a RSS feed; unfortunately the "Fetch Data" module seems to not be able to retrieve the armory data as xml, because wowarmory.com detects that it is not a modern browser, and serves up server-side generated HTML. Does anyone know a way around this?
Other than that, I'd just like to know if anyone else has had luck getting nice achievement feeds onto their blogger.
vBulletin® v4.2.2, Copyright ©2000-2025, Jelsoft Enterprises Ltd.