How to launch window for install flash using javascript? - javascript

am using asp.net with Jquery, Javascript and flash.
Problem: I want to launch a window for install flash at client end(if not flash is not installed).
I used below javascript code to detect if flash is installed or not.
function detectFlash() {
var hasFlash = false;
try {
var fo = (navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash']) ? navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin : 0;
if (fo) {
hasFlash = true;
}
} catch (e) {
if (navigator.mimeTypes['application/x-shockwave-flash'] != undefined) {
hasFlash = true;
}
}
if (hasFlash) {
alert("flash is installed");
}
}
but using above code I got only true or false if installed or not. but if not installed then how can I launch window to install flash using Javascript/JQuery or asp.net
How can I achieve this?

Just make a redirect:
function detectFlash() {
var hasFlash = false;
try {
var fo = (navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash']) ? navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin : 0;
if (fo) {
hasFlash = true;
}
} catch (e) {
if (navigator.mimeTypes['application/x-shockwave-flash'] != undefined) {
hasFlash = true;
}
}
if (hasFlash) {
alert("flash is installed");
} else {
location = "http://www.adobe.com/software/flash/about/";
}
}
You can try to open it in a new tab (browsers may block such actions):
Open a URL in a new tab (and not a new window) using JavaScript
Enabling Flash plugin via JavaScript
Seriously, this is impossible (leave a comment if I'm wrong). Only the user is supposed to be able to enable this. Since this is a browser setting, this is different from a browser to another:
Chrome
Firefox
Internet Explorer
Unless the browsers don't expose a JavaScript API to enable this feature, we have this limitation.

You can redirect the page to this URL once hasFlash is false.
http://download.macromedia.com/pub/flashplayer/current/support/install_flash_player.exe

Related

How to open Twitter and Facebook app with Phonegap?

I am trying to have my PhoneGap application link to open a specific users profile page in the Twitter app. I know not everyone has the Twitter app installed on their device so I wanted to send them to the Play Store to download it if they didn't.
Problem is that every time I tap the link on my Android device I receive an error:
Application Error:
net::ERR_UNKNOWN_URL_SCHEME(twitter://user?screen_name=xerxesnoble)
My JavaScript is as follows:
//If Android
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if (isAndroid) {
alert('Android!');
twitterCheck = function() {
alert('Android!');
var now = new Date().valueOf();
setTimeout(function () {
if (new Date().valueOf() - now > 100) return;
window.open('https://play.google.com/store/apps/details?id=com.twitter.android', '_system', 'location=no');
}, 50);
window.open('twitter://user?screen_name=XerxesNoble', '_system', 'location=no');
};
};
$('.twiterNav').click(function() {
window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');
});
Things that I've tried:
Using twitter:/// instead of twitter://
Adding <access origin="twitter://user?screen_name=xerxesnoble" /> to my config.xml
I'm not sure what else to try, nothing is working for Facebook either but right now I'm focusing on one issue at a time.
The Problem is that the InAppBrowser plugin was not installed. New versions of PhoneGap/Cordova do not come with all plugins installed- instead you choose what you want your App to have access to.
In terminal cd yourApp and $ cordova plugin add org.apache.cordova.inappbrowser
After doing that, it worked perfectly.
EDIT
Just to branch out a little bit more on how I got my .js to check if twitter was installed or not.
I installed another plugin : AppAvailability for iOS and Android
Then I altered my .js to look like this:
//Twitter checker
// If Mac//
var twitterCheck = function(){
appAvailability.check('twitter://', function(availability) {
// availability is either true or false
if(availability) { window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
else{window.open('https://itunes.apple.com/ca/app/twitter/id333903271?mt=8', '_system', 'location=no'); };
});
};
//If Android
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
twitterCheck = function(){
appAvailability.check('com.twitter.android', function(availability) {
// availability is either true or false
if(availability) {window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
else{window.open('https://play.google.com/store/apps/details?id=com.twitter.android', '_system', 'location=no');};
});
};
};
The documentation provided in the AppAvailability plugin was very helpful as well>
Hope that this helps someone!
Just a reference for others who might come here and want a bit more:
I've been able to get this working well (so far) on both iOS and Android, and dynamically falling back to the browser using the code below.
Required plugins are cordova-plugin-inappbrowser and cordova-plugin-appavailability
function openBrowser (url) {
if (!url) {
return;
}
// turn my url into a scheme/intent url
getAvailabilityScheme(url, function (url) {
window.open(url, '_system');
});
}
function getAvailabilityScheme (url, callback) {
var schemeOrPackage;
var schemeUrl;
// check for appavaialbility plugin
if (!window.appAvailability) {
callback(url);
}
// facebook
if (url.indexOf('facebook.com/') !== -1) {
schemeOrPackage = isAndroid ? 'com.facebook.katana' : 'fb://'
schemeUrl = 'fb://profile/' + url.split('facebook.com/')[1];
}
// twitter
if (url.indexOf('twitter.com/') !== -1) {
schemeOrPackage = isAndroid ? null : 'twitter://'
schemeUrl = 'twitter://user?screen_name=' + url.split('twitter.com/')[1];
}
if (schemeOrPackage && schemeUrl) {
window.appAvailability.check(schemeOrPackage, function () {
callback(schemeUrl);
}, function () {
callback(url);
});
} else {
callback(url);
}
}
Using it is easy, just call the openBrowser(url) method with a normal website url. The only issue i found was that for a facebook page, it needs to an ID not the slug name

Chrome returns undefined for cancelFullScreen AND webkitCancelFullScreen

I have written a simple function to toggle Fullscreen Mode on a web application. The application is only required to run in Chrome (eventually deployed under Kiosk mode), but there seems to be some strange behaviour with cancelFullScreen and webkitCancelFullScreen.
For example, here is the stripped down toggleFullScreen function:
var _isFullscreen = false;
function toggleFullScreen()
{
var doc = document.documentElement,
state = _inFullscreen,
requestFunc = (doc.requestFullScreen || doc.webkitRequestFullScreen),
cancelFunc = (doc.cancelFullScreen || doc.webkitCancelFullScreen);
_inFullscreen = !(state);
(!state) ? requestFunc.call(doc) : cancelFunc.call(doc);
}
For some strange reason, Chrome always reports that cancelFunc is undefined, even though requestFunc works fine.
Can anyone explain the reason for this, and a possible solution (without the need for jQuery or similar library plugins)?
With the help of #Tom Chung, and after playing around, it turns out that cancelFullScreen (and similarly webkitCancelFullScreen needs to be called on document, whereas requestFullscreen needs to be called on document.documentElement.
As such, the updated code as follows works fine:
function toggleFullScreen()
{
var doc = document.documentElement,
state = (document.webkitIsFullScreen || document.isFullScreen),
requestFunc = (doc.requestFullscreen || doc.webkitRequestFullScreen),
cancelFunc = (document.cancelFullScreen || document.webkitCancelFullScreen);
(!state) ? requestFunc.call(doc) : cancelFunc.call(document);
}
I am one of the developers working on H5P, which supports fullscreen for all browsers supporting it. Below I have copied the parts of the code needed to exit fullscreen.
First we need to figure out the browser prefix
var fullScreenBrowserPrefix;
// Detect if we support fullscreen, and what prefix to use.
if (document.documentElement.requestFullScreen) {
/**
* Browser prefix to use when entering fullscreen mode.
* undefined means no fullscreen support.
* #member {string}
*/
fullScreenBrowserPrefix = '';
}
else if (document.documentElement.webkitRequestFullScreen) {
var safariBrowser = navigator.userAgent.match(/Version\/(\d)/);
safariBrowser = (safariBrowser === null ? 0 : parseInt(safariBrowser[1]));
// Do not allow fullscreen for safari < 7.
if (safariBrowser === 0 || safariBrowser > 6) {
fullScreenBrowserPrefix = 'webkit';
}
}
else if (document.documentElement.mozRequestFullScreen) {
fullScreenBrowserPrefix = 'moz';
}
else if (document.documentElement.msRequestFullscreen) {
fullScreenBrowserPrefix = 'ms';
}
Here's the code that invokes the correct exit-fullscreen-function:
if (fullScreenBrowserPrefix === '') {
document.exitFullscreen();
}
else if (fullScreenBrowserPrefix === 'moz') {
document.mozCancelFullScreen();
}
else {
document[fullScreenBrowserPrefix + 'ExitFullscreen']();
}
The code is copied from https://github.com/h5p/h5p-php-library/blob/master/js/h5p.js
function toggleFullScreen()
{
//Post author DID NOT provide standards-compliant method at all.
//Standards compliant approaches should detect first.
//Prefixes are eventually removed / performance.
if ()//standards here
{
//standards here
}
else if (document.documentElement.webkitRequestFullScreen)
{
document.documentElement.webkitRequestFullScreen();
}
else if (document.webkitCancelFullScreen)
{
document.webkitCancelFullScreen();
}
}
Not sure why document.documentElement.webkitCancelFullScreen is undefined.
Maybe (I guess) the reason is that full screen effect can only be start once at the same time.
However, document.documentElement.webkitRequestFullScreen is required because document.documentElement give the element that is going to display in full screen.
Work perfectly in http://jsfiddle.net/8mVBK/16/show/
Update.
http://jsfiddle.net/8mVBK/17/

How to check Popup blocker enabled Without loading popup window in chrome using Javascript [duplicate]

I am aware of javascript techniques to detect whether a popup is blocked in other browsers (as described in the answer to this question). Here's the basic test:
var newWin = window.open(url);
if(!newWin || newWin.closed || typeof newWin.closed=='undefined')
{
//POPUP BLOCKED
}
But this does not work in Chrome. The "POPUP BLOCKED" section is never reached when the popup is blocked.
Of course, the test is working to an extent since Chrome doesn't actually block the popup, but opens it in a tiny minimized window at the lower right corner which lists "blocked" popups.
What I would like to do is be able to tell if the popup was blocked by Chrome's popup blocker. I try to avoid browser sniffing in favor of feature detection. Is there a way to do this without browser sniffing?
Edit: I have now tried making use of newWin.outerHeight, newWin.left, and other similar properties to accomplish this. Google Chrome returns all position and height values as 0 when the popup is blocked.
Unfortunately, it also returns the same values even if the popup is actually opened for an unknown amount of time. After some magical period (a couple of seconds in my testing), the location and size information is returned as the correct values. In other words, I'm still no closer to figuring this out. Any help would be appreciated.
Well the "magical time" you speak of is probably when the popup's DOM has been loaded. Or else it might be when everything (images, outboard CSS, etc.) has been loaded. You could test this easily by adding a very large graphic to the popup (clear your cache first!). If you were using a Javascript Framework like jQuery (or something similar), you could use the ready() event (or something similar) to wait for the DOM to load before checking the window offset. The danger in this is that Safari detection works in a conflicting way: the popup's DOM will never be ready() in Safari because it'll give you a valid handle for the window you're trying to open -- whether it actually opens or not. (in fact, i believe your popup test code above won't work for safari.)
I think the best thing you can do is wrap your test in a setTimeout() and give the popup 3-5 seconds to complete loading before running the test. It's not perfect, but it should work at least 95% of the time.
Here's the code I use for cross-browser detection, without the Chrome part.
function _hasPopupBlocker(poppedWindow) {
var result = false;
try {
if (typeof poppedWindow == 'undefined') {
// Safari with popup blocker... leaves the popup window handle undefined
result = true;
}
else if (poppedWindow && poppedWindow.closed) {
// This happens if the user opens and closes the client window...
// Confusing because the handle is still available, but it's in a "closed" state.
// We're not saying that the window is not being blocked, we're just saying
// that the window has been closed before the test could be run.
result = false;
}
else if (poppedWindow && poppedWindow.test) {
// This is the actual test. The client window should be fine.
result = false;
}
else {
// Else we'll assume the window is not OK
result = true;
}
} catch (err) {
//if (console) {
// console.warn("Could not access popup window", err);
//}
}
return result;
}
What I do is run this test from the parent and wrap it in a setTimeout(), giving the child window 3-5 seconds to load. In the child window, you need to add a test function:
function test() {}
The popup blocker detector tests to see whether the "test" function exists as a member of the child window.
ADDED JUNE 15 2015:
I think the modern way to handle this would be to use window.postMessage() to have the child notify the parent that the window has been loaded. The approach is similar (child tells parent it's loaded), but the means of communication has improved. I was able to do this cross-domain from the child:
$(window).load(function() {
this.opener.postMessage({'loaded': true}, "*");
this.close();
});
The parent listens for this message using:
$(window).on('message', function(event) {
alert(event.originalEvent.data.loaded)
});
Hope this helps.
Just one improvement to InvisibleBacon's snipet (tested in IE9, Safari 5, Chrome 9 and FF 3.6):
var myPopup = window.open("popupcheck.htm", "", "directories=no,height=150,width=150,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
if (!myPopup)
alert("failed for most browsers");
else {
myPopup.onload = function() {
setTimeout(function() {
if (myPopup.screenX === 0) {
alert("failed for chrome");
} else {
// close the test window if popups are allowed.
myPopup.close();
}
}, 0);
};
}
The following is a jQuery solution to popup blocker checking. It has been tested in FF (v11), Safari (v6), Chrome (v23.0.127.95) & IE (v7 & v9). Update the _displayError function to handle the error message as you see fit.
var popupBlockerChecker = {
check: function(popup_window){
var _scope = this;
if (popup_window) {
if(/chrome/.test(navigator.userAgent.toLowerCase())){
setTimeout(function () {
_scope._is_popup_blocked(_scope, popup_window);
},200);
}else{
popup_window.onload = function () {
_scope._is_popup_blocked(_scope, popup_window);
};
}
}else{
_scope._displayError();
}
},
_is_popup_blocked: function(scope, popup_window){
if ((popup_window.innerHeight > 0)==false){ scope._displayError(); }
},
_displayError: function(){
alert("Popup Blocker is enabled! Please add this site to your exception list.");
}
};
Usage:
var popup = window.open("http://www.google.ca", '_blank');
popupBlockerChecker.check(popup);
Hope this helps! :)
Rich's answer isn't going to work anymore for Chrome. Looks like Chrome actually executes any Javascript in the popup window now. I ended up checking for a screenX value of 0 to check for blocked popups. I also think I found a way to guarantee that this property is final before checking. This only works for popups on your domain, but you can add an onload handler like this:
var myPopup = window.open("site-on-my-domain", "screenX=100");
if (!myPopup)
alert("failed for most browsers");
else {
myPopup.onload = function() {
setTimeout(function() {
if (myPopup.screenX === 0)
alert("failed for chrome");
}, 0);
};
}
As many have reported, the "screenX" property sometimes reports non-zero for failed popups, even after onload. I experienced this behavior as well, but if you add the check after a zero ms timeout, the screenX property always seems to output a consistent value.
Let me know if there are ways to make this script more robust. Seems to work for my purposes though.
This worked for me:
cope.PopupTest.params = 'height=1,width=1,left=-100,top=-100,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,directories=no,status=no';
cope.PopupTest.testWindow = window.open("popupTest.htm", "popupTest", cope.PopupTest.params);
if( !cope.PopupTest.testWindow
|| cope.PopupTest.testWindow.closed
|| (typeof cope.PopupTest.testWindow.closed=='undefined')
|| cope.PopupTest.testWindow.outerHeight == 0
|| cope.PopupTest.testWindow.outerWidth == 0
) {
// pop-ups ARE blocked
document.location.href = 'popupsBlocked.htm';
}
else {
// pop-ups are NOT blocked
cope.PopupTest.testWindow.close();
}
The outerHeight and outerWidth are for chrome because the 'about:blank' trick from above doesn't work in chrome anymore.
I'm going to just copy/paste the answer provided here: https://stackoverflow.com/a/27725432/892099 by DanielB . works on chrome 40 and it's very clean. no dirty hacks or waiting involves.
function popup(urlToOpen) {
var popup_window=window.open(urlToOpen,"myWindow","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=400, height=400");
try {
popup_window.focus();
}
catch (e) {
alert("Pop-up Blocker is enabled! Please add this site to your exception list.");
}
}
How about a Promise approach ?
const openPopUp = (...args) => new Promise(s => {
const win = window.open(...args)
if (!win || win.closed) return s()
setTimeout(() => (win.innerHeight > 0 && !win.closed) ? s(win) : s(), 200)
})
And you can use it like the classic window.open
const win = await openPopUp('popuptest.htm', 'popuptest')
if (!win) {
// popup closed or blocked, handle alternative case
}
You could change the code so that it fail the promise instead of returning undefined, I just thought that if was an easier control flow than try / catch for this case.
Check the position of the window relative to the parent. Chrome makes the window appear almost off-screen.
I had a similar problem with popups not opening in Chrome. I was frustrated because I wasn't trying to do something sneaky, like an onload popup, just opening a window when the user clicked. I was DOUBLY frustrated because running my function which included the window.open() from the firebug command line worked, while actually clicking on my link didn't! Here was my solution:
Wrong way: running window.open() from an event listener (in my case, dojo.connect to the onclick event method of a DOM node).
dojo.connect(myNode, "onclick", function() {
window.open();
}
Right way: assigning a function to the onclick property of the node that called window.open().
myNode.onclick = function() {
window.open();
}
And, of course, I can still do event listeners for that same onclick event if I need to. With this change, I could open my windows even though Chrome was set to "Do not allow any site to show pop-ups". Joy.
If anyone wise in the ways of Chrome can tell the rest of us why it makes a difference, I'd love to hear it, although I suspect it's just an attempt to shut the door on malicious programmatic popups.
Here's a version that is currently working in Chrome. Just a small alteration away from Rich's solution, though I added in a wrapper that handles the timing too.
function checkPopupBlocked(poppedWindow) {
setTimeout(function(){doCheckPopupBlocked(poppedWindow);}, 5000);
}
function doCheckPopupBlocked(poppedWindow) {
var result = false;
try {
if (typeof poppedWindow == 'undefined') {
// Safari with popup blocker... leaves the popup window handle undefined
result = true;
}
else if (poppedWindow && poppedWindow.closed) {
// This happens if the user opens and closes the client window...
// Confusing because the handle is still available, but it's in a "closed" state.
// We're not saying that the window is not being blocked, we're just saying
// that the window has been closed before the test could be run.
result = false;
}
else if (poppedWindow && poppedWindow.outerWidth == 0) {
// This is usually Chrome's doing. The outerWidth (and most other size/location info)
// will be left at 0, EVEN THOUGH the contents of the popup will exist (including the
// test function we check for next). The outerWidth starts as 0, so a sufficient delay
// after attempting to pop is needed.
result = true;
}
else if (poppedWindow && poppedWindow.test) {
// This is the actual test. The client window should be fine.
result = false;
}
else {
// Else we'll assume the window is not OK
result = true;
}
} catch (err) {
//if (console) {
// console.warn("Could not access popup window", err);
//}
}
if(result)
alert("The popup was blocked. You must allow popups to use this site.");
}
To use it just do this:
var popup=window.open('location',etc...);
checkPopupBlocked(popup);
If the popup get's blocked, the alert message will display after the 5 second grace period (you can adjust that, but 5 seconds should be quite safe).
This fragment incorporates all of the above - For some reason - StackOverflow is excluding the first and last lines of code in the code block below, so I wrote a blog on it. For a full explanation and the rest of the (downloadable) code have a look at
my blog at thecodeabode.blogspot.com
var PopupWarning = {
init : function()
{
if(this.popups_are_disabled() == true)
{
this.redirect_to_instruction_page();
}
},
redirect_to_instruction_page : function()
{
document.location.href = "http://thecodeabode.blogspot.com";
},
popups_are_disabled : function()
{
var popup = window.open("http://localhost/popup_with_chrome_js.html", "popup_tester", "width=1,height=1,left=0,top=0");
if(!popup || popup.closed || typeof popup == 'undefined' || typeof popup.closed=='undefined')
{
return true;
}
window.focus();
popup.blur();
//
// Chrome popup detection requires that the popup validates itself - so we need to give
// the popup time to load, then call js on the popup itself
//
if(navigator && (navigator.userAgent.toLowerCase()).indexOf("chrome") > -1)
{
var on_load_test = function(){PopupWarning.test_chrome_popups(popup);};
var timer = setTimeout(on_load_test, 60);
return;
}
popup.close();
return false;
},
test_chrome_popups : function(popup)
{
if(popup && popup.chrome_popups_permitted && popup.chrome_popups_permitted() == true)
{
popup.close();
return true;
}
//
// If the popup js fails - popups are blocked
//
this.redirect_to_instruction_page();
}
};
PopupWarning.init();
Wow there sure are a lot of solutions here. This is mine, it uses solutions taken from the current accepted answer (which doesn't work in latest Chrome and requires wrapping it in a timeout), as well as a related solution on this thread (which is actually vanilla JS, not jQuery).
Mine uses a callback architecture which will be sent true when the popup is blocked and false otherwise.
window.isPopupBlocked = function(popup_window, cb)
{
var CHROME_CHECK_TIME = 2000; // the only way to detect this in Chrome is to wait a bit and see if the window is present
function _is_popup_blocked(popup)
{
return !popup.innerHeight;
}
if (popup_window) {
if (popup_window.closed) {
// opened OK but was closed before we checked
cb(false);
return;
}
if (/chrome/.test(navigator.userAgent.toLowerCase())) {
// wait a bit before testing the popup in chrome
setTimeout(function() {
cb(_is_popup_blocked(popup_window));
}, CHROME_CHECK_TIME);
} else {
// for other browsers, add an onload event and check after that
popup_window.onload = function() {
cb(_is_popup_blocked(popup_window));
};
}
} else {
cb(true);
}
};
Jason's answer is the only method I can think of too, but relying on position like that is a little bit dodgy!
These days, you don't really need to ask the question “was my unsolicited popup blocked?”, because the answer is invariably “yes” — all the major browsers have the popup blocker turned on by default. Best approach is only ever to window.open() in response to a direct click, which is almost always allowed.
HI
I modified the solutions described above slightly and think that it is working for Chrome at least.
My solution is made to detect if popup is blocked when the main page is opened, not when popup is opened, but i am sure there are some people that can modify it.:-)
The drawback here is that the popup-window is displayed for a couple of seconds (might be possible to shorten a bit) when there is no popup-blocker.
I put this in the section of my 'main' window
<script type="text/JavaScript" language="JavaScript">
var mine = window.open('popuptest.htm','popuptest','width=1px,height=1px,left=0,top=0,scrollbars=no');
if(!mine|| mine.closed || typeof mine.closed=='undefined')
{
popUpsBlocked = true
alert('Popup blocker detected ');
if(mine)
mine.close();
}
else
{
popUpsBlocked = false
var cookieCheckTimer = null;
cookieCheckTimer = setTimeout('testPopup();', 3500);
}
function testPopup()
{
if(mine)
{
if(mine.test())
{
popUpsBlocked = false;
}
else
{
alert('Popup blocker detected ');
popUpsBlocked = true;
}
mine.close();
}
}
</script>
The popuptest looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Popup test</title>
<script type="text/javascript" language="Javascript">
function test() {if(window.innerHeight!=0){return true;} else return false;}
</script>
</head>
<body>
</body>
</html>
As i call the test-function on the popup-page after 3500 ms the innerheight has been set correctly by Chrome.
I use the variable popUpsBlocked to know if the popups are displayed or not in other javascripts.
i.e
function ShowConfirmationMessage()
{
if(popUpsBlocked)
{
alert('Popups are blocked, can not display confirmation popup. A mail will be sent with the confirmation.');
}
else
{
displayConfirmationPopup();
}
mailConfirmation();
}
function openPopUpWindow(format)
{
var win = window.open('popupShow.html',
'ReportViewer',
'width=920px,height=720px,left=50px,top=20px,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=1,maximize:yes,scrollbars=0');
if (win == null || typeof(win) == "undefined" || (win == null && win.outerWidth == 0) || (win != null && win.outerHeight == 0) || win.test == "undefined")
{
alert("The popup was blocked. You must allow popups to use this site.");
}
else if (win)
{
win.onload = function()
{
if (win.screenX === 0) {
alert("The popup was blocked. You must allow popups to use this site.");
win.close();
}
};
}
}
As far as I can tell (from what I've tested) Chrome returns a window object with location of 'about:blank'.
So, the following should work for all browsers:
var newWin = window.open(url);
if(!newWin || newWin.closed || typeof newWin.closed=='undefined' || newWin.location=='about:blank')
{
//POPUP BLOCKED
}

Here is a new type of ad javascript by change "window.opener.location", how can i block it?

One of my friend climes that his Chrome browser tab sometimes changed into "tamll.com", which was the biggest shopping website in China.
At first I think it may be caused by a malware. But he has a clean os, and he checked everything in his computer.
Then I found this javascript. The code is always in the bottom of this question. And this script is being included in "bbs.gfan.com".
The script use window.opener.location to change another browser tab's webpage. When you open any pages in "bbs.gfan.com" from google.com(for example search "bbs.gfan.com" in google and click the first answer), this script check if the window.opener is not null, and set the window.opener.location to _5had0w.mall. Then the window.opener tab will be jumped to the new address.
Is there any way to block a script when it try to change window.opener.location? Or is there a way to directly disable the window.opener.location?
I think a normal webpage will never change this variable, it may only use by a ad script like this.
This kind of ad script made me feel sick. It is not only open a ad webpage but also another webpage will gone...
if ("undefined" == typeof (_5had0w)) {
_5had0w = [];
_5had0w.ssite = new RegExp("(www.baidu.com)|(www.google.c)|(www.youdao.com)|(search.cn.yahoo.com)|(search.yahoo.com)|(114search.118114.cn)|(bing.118114.cn)|(search.114.vnet.cn)|(bing.com)|(www.soso.com)|(www.sogou.com)|(www.taobao.com)|(gougou.com)|(www.gouwo.com)|(cache.baidu.com)|(m.baidu.com)|(baidu.asp)|(hao123.com)|(265.com)|(114la.com)|(115.com)|(etao.com)", "i");
_5had0w.win = window;
try {
if (parent && parent.f && parent.document.getElementById("fulliframe")) {
_5had0w.win = parent
}
} catch (e) {}
_5had0w.getcookie = function (sName) {
var aCookie = document.cookie.split("; ");
for (var i = 0; i < aCookie.length; i++) {
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0]) return unescape(aCrumb[1])
}
return ""
};
_5had0w.setcookie = function (sValue) {
date = new Date();
date.setMinutes(date.getMinutes() + 100);
document.cookie = "oc_busy=" + escape(sValue) + "; expires=" + date.toGMTString() + ";path=/"
};
_5had0w.mall = "http://gomallg.blogbus.com/?76";
_5had0w.np = false;
_5had0w.nvIt = function (lochref) {
try {
_5had0w.win.opener.location = lochref
} catch (e) {
try {
_5had0w.win.opener.navigate(lochref)
} catch (e2) {
try {
_5had0w.win.opener.opener.navigate(lochref)
} catch (e3) {
_5had0w.np = true
}
}
}
};
_5had0w.nvUrl = function () {
var _co = _5had0w.getcookie("oc_busy");
if (_co == "" || _co.indexOf("mall") < 0) {
_5had0w.nvIt(_5had0w.mall);
if (!_5had0w.np) {
_5had0w.setcookie(_co + "_mall")
}
}
};
_5had0w.oload = function () {
if (_5had0w.win.opener && "" == _5had0w.getcookie('rf6_auth')) {
if (_5had0w.ssite.test(_5had0w.win.document.referrer)) {
_5had0w.nvUrl()
}
}
};
try {
if (document.attachEvent) {
window.attachEvent("onload", _5had0w.oload)
} else {
window.addEventListener("load", _5had0w.oload, false)
}
} catch (e) {}
}
This web application is taking advantage of the fact that Google and other websites are being opened from gfan.com. Therefore, the gfan.com web application does have some control over the new windows, since it opened them.
If the script at the bottom of the application is what you suspect is causing the problem, you could try one of several adblockers you can get for Chrome and Firefox that are installable as extensions.
If that doesn't work, you could try to edit your host file and point the remote script's domain to 127.0.0.1 so you override the DNS locally. This assumes it is a remote script and not served from gfan.com itself; otherwise, you won't be able to access gfan.com either.
Chrome Adblock is an adblocker you can try.

PopUp Blocker code detection not working

I have turned on PopUp blocker in FF and Chrome.
I have a piece of code to check PopUp is working as:
function checkPopUp()
{
var myTest = window.open("about:blank","","directories=no,height=1,width=1,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
var popUpsBlocked = '';
if (!myTest) {
popUpsBlocked = true;
} else {
popUpsBlocked = false;
}
return popUpsBlocked;
}
its working fine "onload" of the page.
But when i am using it with hyper link onclick, its not working a popup is getting opened.
<a onclick="checkPopUp()" href="#">Test</a>
Browsers allow popups during "click" event loops. Different browsers have different configuration options under user control, but generally the default behavior is that a "click" is treated as a user willingly requesting functionality from a page.
The below code has been tested in FF29.0, IE9, Chrome35.0, Safari and the best part is it is working!!!
var popupBlocker = {
isPopupBlocked: function (width, height) {
setTimeout(function () {
var popup = window.open("");
if (!popup) {
return false;
}
else {
popup.document.open();
popup.document.write("<html><body onload='window.close();'></body></html>")
popup.document.close();
return true;
}
}, 100);
}
};
popupBlocker.isPopupBlocked();

Categories