Open a New tab From iframe javascript event without pop up block - javascript

I have a iframe in a page.
After i successfully send data to server within iframe, the server responds with next URL to open , i want to open the next URL in a new tab or in the parent window.
The Problem i am facing is, the browser treats it as a popup and blocks it.
In chrome it is treated as pop up and in safari it doesn't do anything.
The iframe is pointing to iframe (written in REACT)
The parent URL is main page.
Here is the part of the code that s causing error.
this.props.dispatch(actions.init_db(vals, (error,data)=>{
this.setState({loading:false})
if(error){
this.setState({error:error});
}else{
url=data.next_url;
var win=window.open(url);
win.focus();
}
}));
Basically actions.init_db() calls an ajax function that writes the value to the server.
The server than responds with error or data.If no errror, the data contains Next URL and i want to open the URL.
Any Suggestion or alternate to this solution is highly appreciated.

You can't. If you call window.open from code that isn't running in direct response to a user action (such as a click), it's likely to get blocked by the popup blocker of the browser. The solution is to make sure you're running that code in direct response to a user action. So for instance, when you have the URL from the server, show a div on the page with the link in it for the user to open themselves.

Related

want to display a browser add exception for my https url on iframe in angular

I am displaying a 'https' url on a iframe tag and I have created self signed certificate for that url. But in iframe, when I display the url it does not pop the add exception on the iframe itself but I have to manually open that url into a different tab and then accept the exception.
I want to display that url exception on the iframe so that I can add the exception then and there instead of opening it different tab.
Please help me with this if it is possible with iframe or any other way. I am fairly new to javascript.
Thank you.

Open and then kill a browser window in a nodejs script?

So I've been trying to write a script that needs to open a browser window to do google oauth. Now the problem is I can use open to open the browser window, but I can't find a way to close it after the auth happens. It just stays there.
i'm not sure this what your asking, but you can do this by sending the response to the page like code shown below.
router.get('/yourpage',(req, res) => {
res.send("<script>window.close();</script > ")})
so basically when your page gets opened this will send the close script from the server-side to the client by instructing close the window.

JSON or AJAX REQUEST not shown in console when open page in new tab

I am trying to open link in new tab using target="_blank", for some reason its not working.
link.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="somejs.js"></script>
somejs.js
function loadFunction() {
$.getJSON("data.php", function (data) {
info = data.info;
console.log(info);
});
}
loadFunction();
As you see, somejs.js contains JSON script.
When link.php's page is loaded in a new tab, the JSON REQUEST is not shown in the console. However if I refresh the page first then the REQUEST is shown in console. JSON REQUEST is also available when I try to open the page in a new tab manually.
What is the matter?
here is the screenshot
direct link or refresh
new tab
From the comments I believe there is a confusion of terms. When you mention you don't see the request in the console I believe you mean the Network debugger.
The console is something different, and that is why other users told you to use console.log() if you want anything to be seen on the Javascript console.
What you are experiencing is something particular of the browser. If you have the Debugger/Inspector open before loading the page the Network tab should show any request done via AJaX. If it doesn't then it is some technicality on the browser side that prevents from showing it, but the call is done (as you can test by console.log()).
When link.php's page is loaded in a new tab, the JSON REQUEST is not
shown in the console.
JSON REQUEST is also available when I try
to open the page in a new tab manually.
From these two comments I deduce the only case when you don't see the call on the Network tab is when you have page A with a link that opens link.php on a new tab.
If that's the case then that's because the debugger you are looking at belongs to page A. You then open a new tab, which does not have the debugger open yet, and any request done from link.php does not have any place to be shown at.
If you refresh link.php with its own debugger panel open, then you do see the request. And the same if you call link.php manually in a new tab which already has the debugger open.

Never Show Window On Page Launch

I am using C# and asp.net to launch a webpage that I am passing parameters to. That works well! I come from a Windows.Forms background so please forgive me if I am trying to achieve the impossible. What I would like is set the Visibility property of the program (either IE or chrome) to false so the user never sees that a webpage is being launched. I have been using this JS function to close the page, but it seems that the page must completely load before closing which sometimes can take a few seconds.
Does asp.net have the capability to achieve such? And this is my JS code I have been using
string close = #"<script type = 'text/javascript'>
window.returnValue = true;
window.close();
</script>";
base.Response.Write(close);
If you don't want the User to see the page, I assume you just want to post some information to the page. In that case, make an HTTP request via c# code, instead of opening the webpage up in a browser.
On the Project Properties page, Web tab, Start Action section, click the radio button for "Don't open a page. Wait for a request from an external application".

Cross Origin - window popup (window.opener is null)

What i wanted to do:
From parent window on user click open new window source is Third Party URL (different domain)
User Authenticate in Popup and then Third party submit success data on Redirect page. (Like Twitter)
From Child Window (PopUpWindow) i have to send data back to Parent window.
what i did
var windowReference= window.open('https://ThirdPartyURL', 'CrossDomain', 'width=840,scrollbars=yes,top=0');
window.parentMethod= function (input) {alert(input)}
window gets open in new window User gets authenticate and get returned data on Redirect Page
on Redirect page (child window)
window.opener.parentMethod(response);
in Firefox its working but in IE
window.opener null . Reason is cross domain . if Third party URL is in current domain then it works fine but if its cross domain windowReference gets null
to get it working i have to change Internet Settings->Security->Check Enabled
its almost impossible to do at every client machine.
i have tried to used Postmessage but it has support for IE10 and in IE8 and 9 it has support for Iframe where as in my case Third party has disabled IFRAME embedding.
can some one help me how to over come this issue . any help will be appreciated
Short answer: you can't. The cross origin policy has as a reason exactly not allowing you to do what you want (the so another site won't run js on yours and the other way around).
To get around that you need to find another way to send data (usually server side -> curl requests).

Categories