How can I unblock pop-up in any browser using Javascript - javascript

Help needed.
I have done a lot of R&D to come up with the solution on unblocking the pop-up on the browser but not been able to resolve this issue so I would like to know your valuable thoughts/solutions.
My requirement;
1. When user fills the form and get the successful message, then the new window appears in the same browser with external link.
I have tried the below tricks to solve this.
I have write the below code for new window.
window.open("/","NewWindow",'width=100,height=100');
OR
setTimeout(function() {
window.open("/","NewWindow",'width=100,height=100');
},1000);
OR
open("/","NewWindow",'scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=100,height=100,left=-1000,top=-1000');
Also I'm created an anchor and trigger click event, but pop-up is still getting blocked.
Please help.

I doubt it is possible. If a popup is blocked on the user's end, it's blocked. You cannot programmaticly unblock it.
However, you got alternatives:
You can use modals: Although it looks like one, a modal is not a popup, and it won't be blocked.
You can also ask the user to unblock your site from the popup blockers (show them a warning). Many sites do this.

Related

How to prevent page from getting redirected via document.location?

I am making an auto-clicker for a website. Sometimes, when the element is clicked, it will navigate to a different page, presumably via document.location. I would like to prevent the redirect, and keep the user on the same page. The closest solution I've acheived so far is by using
window.onbeforeunload = function(){
return 'Are you sure you want to leave?';
};
which asks the user to confirm if they would like to remain on the page. If the user clicks cancel, then they remain on the current page, which is ideal.
The issue is that I have to manually click cancel on the prompt, which is not ideal and I don't believe I can make JavaScript auto-click cancel.
So is there a way for me to prevent the redirect, without the prompt appearing?
I figured it out. It is possible. I just need to use:
Object.freeze(document.location);
An interesting fact
It's possible to enter in any javascript to any existing webpage.
You can do this by injecting a via third party script, or just manually enter it into the inspector like this:
window.onbeforeunload = fuction () { return false;}
Websites commonly include references to third party scripts like analytics, ads, tools, libraries etc, and all of them could theoretically include a malicious script.
This is technically hijacking the existing website. It would be easy to hack peoples websites because of this, which is probably why the prompt is there as a mediating safe measure from web browsers.
Note if you close the web browser down, it won't prompt, so this method is not a fail safe anyway.
Conclusion.
No, it's not possible.
Alternative
Regarding the auto clicker redirect, why don't you simply put in an if condition that doesn't redirect them?

How do I open a link to a website on a new window in a browser and block the current website until the user finish or close the new one?

Currently I'm working with Mercado Pago API, but the thing is that I want when the user clicks the pay button, I want to open a new window in the browser (chrome, firefox, etc.) in the middle of the screen where is going to fill his credit card number and all that stuff meanwhile i want that the background site (I mean the main site where the user clicked on pay) to be blocked, like with darker colors, and not be able to do anything in that site until the user close the new window or he finish with the payment. I've been looking on the internet but I haven't found anything related to the blocked site. Maybe you could help me or have any idea to make that. thanks in advance.
I can't make comments, so sorry in advance for this being an "answer". But are you not able to store information about what the user has selected and then use the current page to process the payment, then bring back or send off what they wanted? perhaps using AJAX to run a PHP page that stores something. Just a suggestion but not entirely an answer, because AFAIK you can't "block" tabs as that could be very dangerous and could be used for the wrong reasons.
The task you want to do requires both back-end programming (php/server-side) and a bit of front-end jquery(js) + ajax.
For front-end something like this could be your start.
Bootstrap Static Modal Example.
And you would need to put your form there, submit it via ajax, and on success close the modal.
I hope this could help you a bit, and get you started in the right direction.
Note: This is not particularly safe. (It's not hard to hide the modal and fiddle around the page in the background.

How to redirect and open new tab in one click

In page one : Form and submit to page two
page two : Insert data, open new tab and redirect to page one
I'm using
window.open("pdf_order.php?p=<?=$paper;?>","_blank");
window.location = "page1.php";
but, It's doesn't work because block popup on browser.
According to your question, you want to issue a window.open call when you arrive on "page two."
You can't, because that's what scuzzy websites used to do, and this is the whole point of popup blockers. Instead, you'll need to adjust the clickflow so you're not trying to do that.
This is a question of the type: Doing X is not allowed. How to do X?
If a popup blocker allowed you to do a popup, it would be a very bad
blocker, and people would not use it.
Please understand that a popup blocker is always a step ahead of you: it uses interface to a concrete Web browser which in turn take a total control of all rendering and scripting on the client side. And your application is supposed to work with all kinds of HTTP client software and be somewhat abstracted from it. From this point, it's easy to understand that it's much easier for a blocker to block your code then break this blocking.
found this answer on http://www.codeproject.com/Questions/474314/PopUpplusBlockerplusisplusdisplayingpluswhenplusop
try AJAX

how to make javascript popup unblocked in any browser without user interference?

I have used popup at many places in my website (its in PHP with Mysql DB and lots of javascript). These are mostly been blocked my browsers, which restricts user to move ahead. what should do in my code so that my popups becomes Popyp blocker independent..
Use Jquery Dialogs http://jqueryui.com/demos/dialog/ they are purely javascript and so popup blockers will not block this
Make sure your popups's URL is on the same domain as the main site. Using a link with 'target="_blank"' will never get blocked unless it was manually blocked as the user did the action himself. Switch to alerts and prompts instead of popups.
Not a direct answer but may be Floating div is a good replacement. Build a js dialog box.

Facebook Connect Bug - JavaScript Refresh

Facebook Connect has a recent bug that is causing the permissions pop-up window to not close and refresh the parent window as it is designed to do. Instead, after approval by the user it attempts to load the page directly in the pop-up window which is an awful user experience and really hurting our registrations. You can see the bug by registering for our site using Facebook Connect: http://alltrails.com
The URL of the page after the user connects that Facebook Connect is incorrectly loading in the permissions pop-up window is of the form:
http://alltrails.com/?installed=1&session={"session_key":"2.Gu0duOqdElNjXRac5wnetw__.3600.1283799600-1486832834","uid":1486832834,"expires":1283799600,"secret":"tKFaEgBTF9RJeuQZfYUSCw__","base_domain":"alltrails.com","sig":"a8dd9f75418b530ae6c3d935e14274c4"}
I'm hoping that someone much better at JavaScript than myself could suggest a simple code snippet that we could add to our homepage that would only be invoked if the page URL includes '?installed=1' and would do the following to allow the same user experience as Facebook Connect was intended to provide:
Close the permissions pop-up window
Load the appropriate page http://alltrails.com/register/facebook in the original parent window
I've tried to do this a bunch of different ways but haven't had any luck with getting it to work correctly. Thanks in advance for your help!
It's a (unconfirmed) bug.
http://bugs.developers.facebook.net/show_bug.cgi?id=12260
Hopefully it gets more votes so it gets fixed - vote people!
In the meantime, i am (attempting) to employ the following 'creative workaround':
Add logic to my Default.aspx page to detect that URL they are redirecting to in the popup.
Redirect to my page, FacebookInboundAuthorization.aspx, preserving querystring.
On load of that page, register some JavaScript to close the popup and manually fire the "onlogin" event handler for my button.
EDIT - Another possible solution
So i do something like this for the "Disconnect from Facebook" button, which has a similar bug which has been in FBC from day 1. If the user is already logged in, and you click the "Disconnect from Facebook" button, the "onlogin" handler is not fired.
So what i ended up doing is replacing the Facebook Disconnect button with my own regular anchor tag, mimicing the Facebook CSS. This way i can have full control over the click event (fire the function i want).
So, this principle could (theoretically) be applied to this current bug.
That is, after you do FB.Init on client-side:
Check FB auth status using FB.Connect.ifUserConnected
If user is connected, hide the regular FB:Login button, and show your "fake" FB Login button. Copy across the "onlogin" function from your regular FB:Login button to your fake button as the onclick event.
Your Fake FB Login button would be a regular anchor tag, with the same CSS applied to the regular FB Login buton.
So essentially, if the user is already connected, we don't really need FB's intervention for authentication, we can just do whatever we want (request perms, redirect, etc).
That should work.
Unfortunately i have higher priority things i need to work on, but it sounds like this is top priority for you.
So give that a go, hope it helps.

Categories

Resources