views:

23

answers:

1

I'm currently stumped on how to approach this situation.

my application is a content sharing system that requires the user to load my javascript file that would position a button for sharing and on click it would automatically collect content from the page and publish it to my application.

My question is:

What is the best way to find the correct content without having the webmaster add extra tags and such, want a method extremal fast and reliable!

also if theres any libraries out there for doing this can you please link them.

Regards

A: 

Its tough to try without any sample code, but here is a half-baked idea...

I assume you only want the webmaster to include the SCRIPT tag and you do the rest?

In that case I would have your embed code look something like this:

<SCRIPT SRC="path/to/code.js?PARAMS" ID="MY_THING"></SCRIPT>

within your code I would have your code look for the SCRIPT tag with the id "MY_THING". Once you have that element you would look at the src attribute and analyze the PARAMS

PARAMS would describe the DIV or classNames of there the content lived. You'd have to figure this out but IDs are easiest or basic path maybe?

Example:

Lets say you want to garb a specific image, and caption (of which there is one, not multiple in this case):

<div class='photo'>
  <img id='thisphoto' src="blah.jpg">
  <p class='caption'>Blurb</p>
</div>

Then PARAMS would be:

?img=thisphoto&caption=p.caption

Going with this logic, if the image didn't have a conienent ID you could grab it with:

?img=div.photo>img&caption=p.caption

You'd need to break that apart within your JS to figure out which elements to look at.

Depending on your needs this could get very complicated, but would work for a straight-forward set of known data.

my 2 cents

Minor Update:

I should also add that you could add custom attributes into the SCRIPT tag:

<SCRIPT photoSrc='ID_OF_ELM' captionSrc='DIV.CLASSNAME'...

Again, could get complicated fast

michael
but even if i did implement a way like this, it still leaves the problem of the webmaster not placing the correct ids,classes,filters etc and so i would need a fallback.
RobertPitt
Someone is going to have to determine the 'filter'. Either you provide it, or they do. Any other solution is guesswork.
michael