Tag: html

(Even) better parsing of HTML tags

It’s no secret that Spin Rewriter is an absolute champ when it comes to parsing HTML code that your texts have been wrapped into.

In other words, Spin Rewriter doesn’t play nice just with simple texts that consist of headings and paragraphs and little else.

It also plays nice with texts that include HTML tags, links, images, unordered and ordered lists, italics, bolded sections, etc. All of this extra HTML code that’s usually thrown into the middle of sentences trips up most text-processing software products out there, but it’s been one of our primary focuses since the beginning — and it shows.

With today’s update, we’ve taken care of two very minor, very sporadic issues that have popped up from time to time when parsing particularly tricky bits of HTML code inside your texts. So, at this points, we’re quite confident that when it comes to HTML, Spin Rewriter is — as usual — the undisputed market leader.

Here’s to you making the most of the power Spin Rewriter brings you! 😀

Prevent users from accidentally leaving the page [JavaScript]

Sometimes your users might lose important information that they’ve been working on by accidentally leaving the page. They can either press the “previous page” or “next page” button by accident, or they can hit the “backspace” key on their keyboard, inadvertently click a link etc.

Luckily you can prevent them from losing their progress by using the following bit of JavaScript code:

window.onbeforeunload = function() {
    if (your_users_might_lose_their_work) {
        dialog_text = "IMPORTANT: Are you sure you want to leave this page?\n\n";
        dialog_text += "WARNING: If you leave this page, you will lose all your current progress.";
        return dialog_text;
    }
};

This code works perfectly fine with all modern browsers, with one small disclaimer: Firefox will not show your custom warning to your users, instead it will simply state “This page is asking you to confirm that you want to leave – data you have entered may not be saved.” However, that’s exactly what you usually want to say in this situation anyway.

Get HTML of selection [JavaScript]

I just recently needed to get the actual HTML of what was selected in a browser. Selected as in “you drag your mouse across some text and it turns blue”. So I came up with this nifty piece of JavaScript code that works quite flawlessly across all major browsers (yes, including IE).

/**
 * gets the current selection, including HTML code
 * @return string
*/
function getSelectionHTML() {
	var userSelection;
	try {
		if (window.getSelection) {
			// W3C ranges
			userSelection = window.getSelection();
			if (userSelection.getRangeAt)
				var range = userSelection.getRangeAt(0);
			else {
				var range = document.createRange();
				range.setStart(userSelection.anchorNode, userSelection.anchorOffset);
				range.setEnd(userSelection.focusNode, userSelection.focusOffset);
			}
			var clonedSelection = range.cloneContents();
			var div = document.createElement("div");
			div.appendChild(clonedSelection);
			return div.innerHTML;
		} else if (document.selection) {
			// Internet Explorer selection
			userSelection = document.selection.createRange();
			return userSelection.htmlText;
		} else {
			return "";
		}
	} catch(e) {
		// an error occurred - supposedly nothing is selected
		return "";
	}
};

Okay, I give up – here’s my blog!

As many of you already know, I’ve been more than active in the online business for the last couple of years (has it really been 4 years already?!), but I was always simply posting comments to existing blogs of our projects / products / services, commenting on marketing and web-dev forums, and I never had my own blog.

Over the time, there were so many fellow internet marketers asking me to start a blog to write down my thoughts and code tutorials etc. that I eventually had to give it a thought. And here it is. Aaron’s blog about internet business in general, business principles, inspiration, search engine optimization, marketing, revenue generation and LOTS of code.

I hope you like it! 😉