views:

40

answers:

2

Check this link. http://dev.twitter.com/pages/share_bookmarklet

Drag bookmarklet to your bookmark-bar and click on it. It will open a pop up window.

Why is my firefox/ie/chrome not blocking this?

Thanks

javascript: 
function loadScript(scriptURL) {
    var scriptElem = document.createElement('SCRIPT');
    scriptElem.setAttribute('language', 'JavaScript');
    scriptElem.setAttribute('src', scriptURL);
    document.body.appendChild(scriptElem);
}
var url = 'http://api.bit.ly/shorten?version=2.0.1&login=tweetthees&apiKey=Rxyz&longUrl=' + document.location;
var longUrl = document.location;
loadScript(url + '&callback=tweetme');
function tweetme(json) {
    var shortLink = json.results[longUrl].shortUrl;
    var finalUrl = 'http://twitter.com/home?status=Reading: ' + document.title + ' ' + shortLink;
    window.open(finalUrl, "Share link", "width=1024,height=400,location=1,status=1,scrollbars=1");
}
+1  A: 

Bookmarklets aren't typically blocked by the browser's popup blocker, you're intentionally invoking it....so it's a popup you wanted, presumably, since you added the bookmarklet in the first place.

Nick Craver
thanks for the answer. I wrote this bookmarklet which is similar to what twitter is doing.
priyank
Updated my post. If I run this, browser blocks the popup.
priyank
+3  A: 

Usually popup-blocker don't block popups general, they only block popups that should be opened without any user-action. Thats not the case if you use bookmarklets, because the user selects the bookmarklet before the popup opens. When using a bookmarklet it may be, that this would'nt get observed by a popup-blocker, like Nick said(I think there is no need to, a bookmarklet should be trusted).

But in a webpage this popup also would'nt be blocked, if the function was called following a click-event.

Dr.Molle
hi.. thanks for your comment. I have updated my post. I have added bookmarklet code which opens a pop up but it is blocked by browser
priyank
I can't tell you concrete, how they block(as there are a lot of blockers, everyone may have his own behaviour). So my guess: It doesn't depend on the time, your example would open the popup not directly, it first has to load some ressources(I tried with a simple timeout, this does'nt instructions. be blocked). I rather think, that it's a problem of accessing the instructions. There is no direct context between the bookmarklet and the function that opens the popup(the instruction to call the function comes later with the loaded script, which, so I assume, isn't trusted anymore).
Dr.Molle