I’m a little baffled by why this is happening…
I have the following code saved as a standalone html file on my PC’s desktop:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
function load() {
$.getJSON( "http://somedomain.json?&jsonp=?", function(json) {
$.each(json.data.children, function(i,item){
var iData = item.data;
var commentLink = "www.somedomain.com" + iData.permalink;
$("<a href='"+commentLink+"'>Comments</a>").appendTo("#content");
$("<br/>").appendTo("#content");
});
});
}
</script>
</head>
<body onload="load()">
<div id="content" />
</body>
</html>
It all works fine, except that the links end up looking like this:
file:///C:/Users/myname/Desktop/www.somedomain.com/comments/somesubdomain/
Is this expected behavior for what I am doing, or did I do something wrong?
I am opening the standalone html in firefox FWIW.
Thanks.
I think this is happening because you are not referencing the
http://in yourcommentLinkvariable.The browser then recognizes it as a local file, local to your desktop.
If you change
var commentLink = "www.somedomain.com" + iData.permalink;to
var commentLink = "http://www.somedomain.com" + iData.permalink;I think it should work.