New window opens when button is clicked but not when using .onclick() - javascript

I am using software that creates all the HTML/XML so I don't have this and I have created a button to open a form in a new window. When I physically click on this button, everything works. However when I run the code onload, I get a message saying that the page is blocked and I need to remove any popup blocker
var button = getElement("GUID_of_Button");
button.click();
This code works if I set to open the form in the same window as a tooltip but not as a new window. I tried on Chrome, Firefox and IE with same results. (no console error)
Not sure if this helps (get this when I inspect element)
<input name="buttoncontrol0F09F8F7" id="ID_buttoncontrol0F09F8F7" value="Click here" type="submit" title="Click here" class="Button_Standard" style="cursor: pointer;">==$0
Naturally I can remove any blockers but as this is for the whole office, I can't ask everyone to do this just so I can get this to work. Any advise is appreciated.

This is a feature of modern browsers that restricts the opening of new windows to user-initiated actions.
This is important as it mitigate security risks and gets rid of the most obnoxious advertising.
Unless you can get everyone to change their browser settings, you won't have a new window opened automatically.
Depending on the data you need to display, you could consider alternative to new windows such as modals / pop-ins. Take a look for example at Bootstrap's modal.

Popup windows are generally used for advertisement and these windows will be opened without permission of user. Inorder to prevent this, most of the web browsers comes with popup blockers which should be explicitly configured by user if they want to automatically open something in a new window.
If you want to use this featue, you'll have to ask users to configure popup blockers in their web browser.

Related

Xrm.Utility.openwebresource opens new tab

We have an onprem crm 2016. I'm opening an html webresource on a click of a ribbon button. I'm using Xrm.Utility.openWebResource(...). The problem with that is we're using IE11 and all users' browsers are configured to let IE decide how to open pop ups.
Guess what, IE decides to open a new tab! Is there a way to open an html web resource in a new window without changing the users' browser options?
Xrm.Utility.openWebResource() performs different in Chrome compared to IE11. Below options are there, pick it what suits you.
window.open()
Unsupported way to open modal dialog - showModalDialog
Xrm.Internal.openDialog()
Source
Xrm.Utility.openEntityForm() has an option to mention as openInNewWindow = true in parameter windowOptions which is not available for openWebResource()

Can't open new tab in JavaScript why? Do I need HTTPS?

When I try to open a new window using:
window.open('url?params','_blank')
it's treated as a popup.
Tried with this to:
<a hred='url?params' target='_blank'>Test</a>
same result.
Tested it on Chrome and Edge.
My site isn't marked as "Secure" in the browser. Does it have to be marked as Secure (HTTPS), to be able to open new windows?
The problem is not with your site being Secure or not.
The thing here is with browsers. They are designed to block new tab or new window as pop ups if they have not being effected/caused form a trusted event. That means the user has to actively click somewhere to open a popup or some submission has to happen to allow the pop up.
The answers from here and here should give you better insights.

Popups being blocked on our app but not others

I am noticing that my share popups are being blocked on our application but not others.
Here is the code execution:
1.) User enters web page.
2.) User clicks on facebook or twitter or googleplus share icon
3.) Onclick event passes the request to an internal controller that saves some information and then redirects back to the originating webpage. This time, however, there is a request parameter that invokes the usage of opening a new window.
The code I have that invokes opening a new window is (for this example we will use facebook):
var url = 'https://www.facebook.com/sharer/sharer.php?u='+copyLink;
window.open(url,'newwindow','width=600,height=600');
Now, if i enable popups it works fine. The problem is the user has to enable popups every time.
Is it a server issue? What is the reason why on other apps they don't have blocked popups but for OUR APP we cannot use popups without enabling popups
Any help would be greatly appreciated.
From what I understand, your application attempts to open a popup window following a page load. The nytimes.com popup appeared in response to a mouse click.
There is an important difference between these two ways to open a popup: the latter follows a user-initiated action but the former does not. As a result, popup blockers will generally block the former but not the latter. A lot of users wouldn't be too surprised if a popup opened when they clicked a button, but they would be more irritated if a popup appeared when a page loaded. The fact that your popup was ultimately triggered by an action on another page doesn't matter - what happens if you manually add to the URL the extra parameter that opens the popup?
Here's an old page on MSDN on popup blockers. It may describe the popup blocker in IE6 (of all browsers), but I think it still provides a reasonable explanation of when popup blockers typically permit or block popups.
Would it be possible to open a popup for your share dialog before calling back to the server? I would expect that opening a popup in the onclick handler would work without needing to explicitly allow popups.

How to allow popups when url loads if it is NOT a physical click by the user in js

I want to allow popups when site loads and if the root cause of an event is NOT a physical click by the user, then it's getting blocked. any help
My code:
$("#buttonBtn").on('click',function(){
openpopup('temp'+id)
});
$("#buttonBtn").trigger('click');
Thanks in advance
With this, if you explicitly click, popup appears. If user comes to this button via keyboard and press Enter or something, I guess this would not be triggered.
$("#buttonBtn").click(function(e){
e.preventDefault();
// some job you will do if clicked, for example, open popup
});
Great example here
You can generally open popups by using window.open. However, most browsers have built-in popup blocker where the user will be notified about a popup and will be asked if he really wants to show it.
The MDN has an informative article about window.open. It also gives some information about popup blockers:
How can I tell when my window was blocked by a popup blocker?
With the
built-in popup blockers of Mozilla/Firefox and Internet Explorer 6
SP2, you have to check the return value of window.open(): it will be
null if the window wasn't allowed to open. However, for most other
popup blockers, there is no reliable way.
Source: https://developer.mozilla.org/en-US/docs/DOM/window.open

Keep Chrome extension popup open while navigating to a new page

I'm developing a Google Chrome extension with a popup (it's a browser action), and it changes the location of the page, which makes the popup disappear. How can I make it stay between page reloads?
You can't. browserAction popups are closed on any activity outside of the popup. You could potentially use Desktop Notifications though.
You'll need to use Background Page, and pull information from it every time you load the popup. Background pages run whether or your extension is currently being used or not.
Not sure if this helps, but from the FAQ:
Can extensions keep popups open after the user clicks away from them?
No, popups automatically close when the user focuses on some portion of the browser outside of the popup. There is no way to keep the popup open after the user has clicked away.
I had to implement a workaround for this as well. In my case, I was trying to use auth0's loginWithPopup. When the popup closed, it returned focus to the chrome window instead of the extension which caused the extension to close before authorization fully completed. I worked around it by opening a new window which acts as a barrier of sorts to prevent chrome's focus from going back to the window the extension was opened from. Anyway, just wanted to put it out there in case it helps someone in the future.

Categories