Skip to main content

Extracting HTML / JavaScript From A Source Listing

If you do any work on your blog, and the template, eventually you will need to extract gadget source code.

The ability to extract source code can be useful in various tasks.
  • Identifying a problem gadget, to others.
  • Publishing a gadget on a separate page, by embedding the code in a page or post.
  • Recovering the content of a deleted gadget.

In each case, use of the proper text browser or source listing is where I start.

Having produced the source listing, I must find and extract the relevant code which represents the gadget in question.

Here is a very basic example, from my Template Laboratory blog. We'll look at a gadget in the sidebar, which I labeled "Empty HTML Gadget".
HTML13
If I locate the gadget, when viewing the blog - and I am logged in as an administrator, I can use the Quick Edit icon (if Quick Edit is enabled), and identify the gadget by the URL. I can do the same, with the "Edit" link in the dashboard Layout wizard.

http://www.blogger.com/rearrange?blogID=6231987187698503326&widgetType=HTML&widgetId=HTML13&action=editWidget§ionId=sidebar-right-1
In this case, I know to search for gadget "HTML13".

I have this luxury, when I am able to view the blog - or to view the dashboard Layout wizard. If I am identifying a problem gadget - maybe a malicious accessory on somebody else's blog, I won't have that ability. Searching for a malicious gadget may require use of two or more source code listings - plus imagination or deductive reasoning.

But, once I identify the gadget, in the source listing, I can start.
See "id='HTML13'"?
Here is the complete section of code, which this gadget produces.
<div class='widget HTML' id='HTML13'>
<h2 class='title'>Empty HTML Gadget</h2>
<div class='widget-content'>
This is a (<span style="font-weight:bold;">somewhat</span>) empty HTML gadget.
</div>
<div class='clear'></div>
<span class='widget-item-control'>
<span class='item-control blog-admin'>
<a class='quickedit' href='//www.blogger.com/rearrange?blogID=6231987187698503326&widgetType=HTML&widgetId=HTML13&action=editWidget§ionId=sidebar-right-1' onclick='return _WidgetManager._PopupConfig(document.getElementById("HTML13"));' target='configHTML13' title='Edit'>
<img alt='' height='18' src='http://img1.blogblog.com/img/icon18_wrench_allbkg.png' width='18'/>
</a>
</span>
</span>
The code which I need is inside the "widget-content" tags.
<div class='widget-content'>

... (Everything here is the "widget content").

</div>
<div class='clear'></div>
<span class='widget-item-control'>
And, in this case, what I need:
This is a (<span style="font-weight:bold;">somewhat</span>) empty HTML gadget.
This is a very simple example - but you will find, consistently, that you need to look for the proper tag set, starting with "<div class='widget-content'>", and ending with the corresponding "</div>".

Identifying the proper closing "</div>" can be tricky. Many gadgets have nested "<div>" ... "</div>" pairs in the "widget content" - so I search for the "<span class='widget-item-control'>" tag, and work backwards from there.
<div class='widget-content'>

...

</div>
<div class='clear'></div>
<span class='widget-item-control'>
And copy the code, from inside the tag set.
This is a (<span style="font-weight:bold;">somewhat</span>) empty HTML gadget.
Once you practice, you'll find it easily enough.

Now, take the extracted gadget code, and publish the gadget to a specific blog page.

Comments

Popular posts from this blog

Stats Components Are Significant, In Their Own Context

One popular Stats related accessory, which displays pageview information to the public, is the "Popular Posts" gadget.

Popular Posts identifies from 1 to 10 of the most popular posts in the blog, by comparing Stats pageview counts. Optional parts of the display of each post are a snippet of text, and an ever popular thumbnail photo.

Like many Stats features, blog owners have found imaginative uses for "Popular Posts" - and overlook the limitations of the gadget. Both the dynamic nature of Stats, and the timing of the various pageview count recalculations, create confusion, when Popular Posts is examined.

Help! I Can't See My Blog!

I just posted to my blog, so I know that it's there. I can tell others are looking at it. But I can't see it.

Well, the good news is you don't have a blog hijack or other calamity. Your blog is not gone.

Apparently, some ISPs are blocking *.blogspot.com, or maybe have network configuration or infrastructure problems. You can access Blogger.com or you can access Blogspot.com, but you can't access nitecruzr.blogspot.com, or bloggerstatusforreal.blogspot.com.

You can't access them directly, that is. If you can access any free, anonymous proxy servers, though, you may be able to access your blog.

Note: You can use PKBlogs with the URL pre packaged. Here is the address of this post (with gratuitous line breaks to prevent the old post sidebar alignment problem):
http://www.pkblogs.com/bloggerstatusforreal.blogspot.com/
2006/07/help-i-cant-see-my-blog.html


And an additional URL, to provide to those suffering from this problem, would be the WordPress version of this post:
ht…