2

I have the following bookmarklet which opens all posts shown in the "Unread topics" page of a SMF forum (the original is a single line):

javascript:(function(){
  var topics = new Array();
  var links = document.getElementsByTagName('a');
  for (var i = 0; i < links.length; i++) {
    if (links[i].href.indexOf('#new') != -1)
      topics.push(links[i].href);
  }
  for (var i = 0; i < topics.length; i++) {
    window.open(topics[i]);
  }
})();

It used to work fine: I opened the page with the links, clicked the bookmarklet, and all the topics would open in new tabs.

After the last Chrome update (my current version is 22.0.1229.79 m, Windows 7 x64), this changed. When I click it, the first topic is opened in a new tab, but the other topics open in popups (I had to authorize them the first time).

My questions are:

  1. How to workaround this issue and restore old behaviour?
  2. What caused this change?
Conrado
  • 716
  • 5
  • 15
  • For me, using a similar bookmarklet, the other pages didn't even open at all. Just opened 2 tabs then quit. Why? Almost certainly to prevent abuses being perpetrated by bad people, and causing collateral damage to us innocents along the way. Probably introducing a setTimeout delay between each window.open will solve the problem. That will force you to approve that site to allow new windows, but luckily in Chrome that is only a one-time problem (unlike some other idiot browsers - IE9). I am not sure how long the delay must be. Once you figure it out, please let me know. – DG. Sep 28 '12 at 08:42

2 Answers2

0

Open a new tab in the background? might help: the answer there recommends using document.createEvent and then initMouseEvent to simulate a ctrl-click - or a meta-click on OS X.

Community
  • 1
  • 1
mblakele
  • 7,782
  • 27
  • 45
0

Try this hack as a work around. Worked for me.

javascript:(function(){
  var topics = new Array();
  var links = document.getElementsByTagName('a');
  for (var i = 0; i < links.length; i++) {
    if (links[i].href.indexOf('#new') != -1)
      topics.push(links[i].href);
  }
  for (var i = 0; i < topics.length; i++) {
    setTimeout(function(){ window.open(topics[i]) }, 500); // ADDED setTimeout
  }
})();

You may need to modify Chrome's popup block settings. If chrome blocks popups, a small icon will appear in the right corner of the URL bar.

You can also edit them directly here: chrome://chrome/settings/contentExceptions#popups

I was able to open at least 30 tabs this way, but there seems to possibly be a limit on the number of tabs that can be opened this way. Playing around with the timeout may help. Or you can open 30, then click again to open 30 more, etc - with a minor code change, obviously. "30" is just an example. Experiment to find an optimum number.

It is worth noting that when I modified the popup blocker settings and used code like yours without setTimeout, what happened is that 2 tabs opened, and then a huge number of new windows opened. I consider this to be bug. I can't see any possible reason to change from tabs to windows under this scenario.

DG.
  • 3,417
  • 2
  • 23
  • 28