Tech Note: LGF Pages Bookmarklet Updated - Popup Blockers Sidestepped

No more need to turn off popup blocking
LGF • Views: 36,819
Image via Shutterstock

There’s a new version of the LGF Pages posting bookmarklet tonight with a very nice new feature: you no longer need to turn off popup blocking in your browser’s settings in order to use the bookmarklet.

This is probably the most common cause of confusion for new LGF users who want to use the “Create a Page” feature to post their own articles, because most of the popular web browsers come out of the box with popup windows blocked, by default, and in some browsers it isn’t very easy to find the settings you need to change. So I’m really pleased to find a solution that lets the “Create a Page” bookmarklet work without having to change any settings. The Internet is confusing enough already.

It’s also nice because now you can turn popup blocking back on (if you previously disabled it to use the bookmarklet) and enjoy a world mostly free of advertising popups.

To install the new version, just right click on the current one in your browser’s bookmarks bar and delete it (if you previously installed it), then drag that big “Create a Page” button to the bookmarks bar in its place.

The technical details of this change, for those interested: I learned something new today, by Googling for “bypass popup blocking” — I discovered that browser popup blockers generally already have a workaround built in. If the popup window is the direct result of a user action, typically a mouse click or tap on a touchscreen, popup blockers will allow the window to be opened. No problem, go right ahead sir, we know you, you’re the guy who clicked.

But if the Javascript code is trying to open a popup window in an indirect or deferred way, it will be blocked. By “indirect,” we can mean inside a timer routine, or in the case of the LGF Pages posting bookmarklet, in the callback function of an Ajax call.

Once I grokked this essential fact about popup blockers, the solution was obvious — open the popup window right away (with a “loading” message) in the direct context of the click, and save that window’s handle. Then instead of using window.open in the callback function, just set the location.href property of the new popup window, to reload the correct page with all of the LGF Pages posting tools ready to go.

(This process happens so fast you may not even see the “Loading…” message when the window first opens.)

Here’s the actual “Create a Page” bookmarklet code in editable form before it’s all scrunched down and transmogrified into the bookmarklet you install.

(function() {
	var postPage = function() {
		var api = 'http://littlegreenfootballs.com/api/0.2/postRegex.json',
			opts = {
				url: api
			},
			browser = navigator.userAgent.toLowerCase(),
			ff = browser.match(/firefox\/(.*)$/);
		if (ff && ff.length > 1 && ff[1] < 21) {
			opts = {
				url:			api + 'p',
				jsonpCallback:	'lgf_api',
				dataType:		'jsonp'
			};
		}					
		jQuery.ajax(opts).done(function(lgf) {
			var esc = function(s) {
					return escape(s).replace(/\+/ig, '%252B');
				},
				ob,
				v = '1.0.6',
				f = a = q = w = '',
				u = esc(location.href),
				d = document,
				t = esc(d.title),
				s = esc((d.selection) ? d.selection.createRange().text : d.getSelection());
			if (u.match(/www\.npr\.org/i)) {
				ob = jQuery('a.download');
				if (ob.length) {
					a = esc(ob.eq(0).attr('href').split('?')[0]);
				}
			} else if (u.match(/www\.rightwingwatch\.org/i)) {
				ob = jQuery('#content-area object embed');
				if (ob.length) {
					if (ob.eq(0).attr('src').match(/www\.youtube\.com\/v\//i)) {
						f = 'https://www.youtube.com/embed/' + ob.eq(0).attr('src').split('?')[0].split('/')[4];
					}
				} else {
					ob = jQuery('#content-area iframe');
					if (ob.length) {
						f = ob.eq(0).attr('src');
						if (f.substring(0, 2) == '//') {
							f = 'http:' + f;
						}
					}
				}
			}
			if (f == '' && lgf !== undefined) {
				ob = jQuery('iframe').filter(function() {
					return this.src.match(RegExp(lgf.regex.embed, 'i'));
				});
				if (ob.length && !u.match(RegExp(lgf.regex.sites, 'i'))) {
					f = esc(ob.eq(0).attr('src'));
				}
			}
			q = (
				'u=' + u +
				'&t=' + t +
				'&f=' + f +
				'&a=' + a +
				'&s=' + s +
				'&v=' + v
			);
			popup.location.href = 'http://littlegreenfootballs.com/weblog/lgf-postpage.php?' + q;
		});
	},
	jqVersion = '1.9.1',
	d = document,
	popup = window.open('http://littlegreenfootballs.com/weblog/lgf-postpage.php?loading', '_blank', 'width=670,height=820,scrollbars=1,status=1,menubar=1,location=1,resizable=1');
	if (window.jQuery === undefined || window.jQuery.fn.jquery < jqVersion) {
		var done = false, s = d.createElement('script');
		s.src = '//ajax.googleapis.com/ajax/libs/jquery/' + jqVersion + '/jquery.min.js';
		s.onload = s.onreadystatechange = function(){
			if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
				done = true;
				jQuery.noConflict();
				postPage();
			}
		};
		d.getElementsByTagName('head')[0].appendChild(s);
	} else {
		postPage();
	}
})();

For more information: LGF Pages bookmarklet.

Jump to top

Create a PageThis is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2023-04-04 11:11 am PDT
LGF User's Guide RSS Feeds

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Cash.app
Recent PagesClick to refresh
The Pandemic Cost 7 Million Lives, but Talks to Prevent a Repeat Stall In late 2021, as the world reeled from the arrival of the highly contagious omicron variant of the coronavirus, representatives of almost 200 countries met - some online, some in-person in Geneva - hoping to forestall a future worldwide ...
Cheechako
2 days ago
Views: 104 • Comments: 0 • Rating: 1
Texas County at Center of Border Fight Is Overwhelmed by Migrant Deaths EAGLE PASS, Tex. - The undertaker lighted a cigarette and held it between his latex-gloved fingers as he stood over the bloated body bag lying in the bed of his battered pickup truck. The woman had been fished out ...
Cheechako
2 weeks ago
Views: 270 • Comments: 0 • Rating: 1