I was messing around with creating a Widget here, and I wanted to take a remote web page, extract some info from it, and display it. I am just familiar enough with the concept of DOM, and recently educated myself enough on Javascript, that I am confident I could do it in about five minutes if I could just get the DOM of the remote web page loaded into a Document object.
But damned if I can't figure out how to do that...
First I tried putting it in an invisible iframe, but the problem is that the iframe might not be (actually, won't be) loaded when you go to start traversing its DOM tree. Then I thought maybe I could have an onLoad event for the iframe document, and go back and fix the HTML then... but it turns out that doesn't work, and a lot of people make that mistake. You have to put the onLoad handler in the frame itself, and... I can't do that, because I don't have control over the remote web page.
So then I started looking into Ajax, which I am pretty sure is the right thing, but I couldn't for the life of me get it to work. I don't really understand how to debug web stuff, so I am stuck. Gah!
On the plus side, I think I learned enough about DOM that I should be able to create a spiffy Javascript thingy to replace the horrible workaround I did to make those "Continue reading..." links appear at the bottom of the appropriate posts. Right now, I put a special label called "more" on each post where I want it (blech!) and then I hacked all the label-referencing code to omit that label. This has numerous disadvantages though.
However, with JS I should be able to get the div that includes the post, then search to see whether it contains the special div tag to hide the text below the fold. Shouldn't be too hard...
Update: Woo hoo, after much fumbling it worked! It probably would have taken me no time at all if I hadn't got confused and started searching for a div tag when I was actually looking for a span tag. D'oh!
Getting rid of that stupid "more" hack also fixed a problem I was having with my tag cloud. Ah, much better... now only if I could figure out AJAX...
Anything but election news
1 hour ago
No comments:
Post a Comment