How to open up a new tab in a pop-up? - javascript

I don't know too much about programming but somehow I managed to make a pop-up window work. However, I need that from inside the new window (the pop-up one) a button on the pop-up will open a new tab. But I don't need the new tab open in the main browser, I want it open in the same pop-up.
Is this possible?
How can I do it?
I show both the pop-up code and the redirection code that is, at present, sending people to another tab in my web browser, but I need to do it in the same pop-up window that is already open. Here is the code in the pop-up:
<!DOCTYPE html>
<html>
<body>
<p>Click aquĆ­ para escuchar Radio Lineage.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
window.open("http://localhost:8000/player/index.html");
}
</script>
</body>
</html>
Here the code of the new tab:
<!DOCTYPE html>
<html>
<body>
.
.
<script type="text/javascript" src="http://hosted.musesradioplayer.com/mrp.js"></script>
<script type="text/javascript">
MRP.insert({
'url':'localhost:8000/stream',
'lang':'es',
'codec':'mp3',
'volume':65,
'autoplay':true,
'buffering':5,
'title':'Radio LineageChile',
'welcome':'Bienvenido a...',
'bgcolor':'#FFFFFF',
'skin':'radiovoz',
'width':220,
'height':69
});
</script>
.
.
</body>
</html>

To open new URL in the same popup window, from your code, I edited to below:
var win = window.open("http://localhost:8000/player/index.html", 'newwin', 'height=200px,width=200px');
after run this line, new popup window will be showed with height=200px, width=200px.
To open new URL in the same popup windown (win), use this line
win.location = "http://www.google.com"/
You can replace google URL by any URL you like.
Hope it helpful!
Good luck.
Johnny

Here the code, just a very small code, that will open the new page as a popup window.Code is working properly.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to open an about:blank page in a new browser window that is 1200px wide and 600px tall.</p>
<button onclick="openWin()">Open Window</button>
<script>
function openWin()
{
var myWindow = window.open("","","width=1200,height=600");
}
</script>
</body>
</html>

<script type="text/javascript">
win = null;
function openPopup(){
win = window.open("http://www.google.com", 'newwin', 'height=200px,width=200px');
}
function openOtherUrl(){
win.location = 'http://www.yahoo.com';
}
</script>
you can use this code, I change URl successfully with it.
Hope it will be helpful for you!

Related

How to execute a javascript function in a new window on a buttonclick in html

How to call a javascript function(Jitsi Meet API) on button click and open the result(meeting) in a new window, in this case the function has to open up a new Jitsi meeting
I have a javascript function that calls the Jitsi Meet API and opens up or launches a new meeting on button click?
//Javascript function to launch the meeting on the button click
$('#btnStart').on('click',function(){
Launch();//need to open the new window here and execute this function in new page
});
As of now, the meeting launches on the same page, It would be really helpful if the meeting opens up in a new window on button click.
In simple terms, button click on this page should open up a new window and execute the function in the new window. I want to know how this can be achieved and by using what method.Do guide with an example snippet
Thanks in advance
<html>
<head>
<title>Launch Page</title>>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="javascript.js"></script>
<script>
$('#btnStart').on('click',function(){
Launch();
});
</script>
</head>
<body >
<div id='meet'>
<button id='btnStart' class ="button">Launch</button>
</div>>
</body>
</html>
Below is the function and the file that has to be executed in a new window on button click- javascript.js
var api=null;
function Launch(){
const domain = 'your.domain.com'
const options = {
roomName:'room123',
width: "100%",
height: "100%",
parentNode:document.querySelector('#meet'),
interfaceConfigOverwrite: { SHOW_JITSI_WATERMARK: true,SHOW_WATERMARK_FOR_GUESTS: true, DEFAULT_BACKGROUND: "#212529",
DEFAULT_LOCAL_DISPLAY_NAME: 'oc' ,TOOLBAR_BUTTONS: [
'microphone', 'camera', 'desktop', 'fullscreen',
'fodeviceselection', 'recording', 'profile', 'chat',
'settings', 'raisehand','info','hangup',
'videoquality', 'filmstrip', 'stats',
'tileview'
]}
};
api = new JitsiMeetExternalAPI(domain,options);
}
After researching a while, I finally figured it out
I made use of the window.open() in the current HTML script to open up new window and made use of document.ready(){} and loaded the script inside this function on loading the new window.
Voila!! It worked as per my requirement instead of calling the javascript on src i.e.,
<script src ="example.js"></script>
If you want to open a document/html in a new window and not tab on button click or link use the window.open() as shown below
Syntax
window.open(URL, name, specs, replace)
window.open("example.html","windowname","_blank","height=500,width=500");
This is what my function looks like now after modification
example.html
<html>
<head>
<title>Welcome to My HTML</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(function(){
$('#btnStart').on('click',function(){
window.open("example2.html","newWindow","_blank","height=500,width=500");
});
});
</script>
</head>
<body>
<div>
<button id='btnStart' class ="button">Launch New WIndow</button>
</div>
</body>
</html>
This is where the window.open() redirects to.
example2.html
<html>
<head>
<title>My page 2</title>
<script>src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"
</script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
//Printing log to check if DOM is loaded
$( document ).ready(function() {
console.log( "Ready" );
});
//Load your function/script to execute here
$(document).ready(function(){
//Your function goes here or the script you wanna run
});
</head>
</html>
Conclusion
This tutorial demonstrates on how to open a new window(not tab) on button click and execute a javascript function and or script on opening the window.
Regards

When you open the Alert window in the Popup window, the popup window disappears

For IE11.
If you open the alert window in the popup window of A, the popup window disappears once, and when you check again, the popup window appears.
For other browsers (Chrome, FF, Edge), the alert appears in the popup window.
I wonder if there is a solution.
Can't reproduce the problem on my side. According to your description, I create a sample using the following sample code, it seems that everything works well:
code in main page:
<button onclick="myFunction()">Open new window</button>
<script>
function myFunction() {
window.open("popuppage.html","_blank","wight=900px, height=600px")
}
</script>
code in popuppage.html:
<head>
<meta charset="utf-8" />
<title></title>
<script>
function myfunction() {
alert("Hello");
}
</script>
</head>
<body>
<a id="btnshowalert" href="#" onclick="return myfunction();" > show alert</a>
</body>
The result as below:
Please try to clear IE browser cache and history, then create a new page to test above code or re-test your code. If still not working, you could try to reset Internet Explorer settings and share your code.

addition Blank window opened with pdf file in javascript

I want to open a pdf file when page is getting loaded (onload), I done it through calling javascript function on onload action ,I can open a pdf in adobe reader ,but issue is I got new Blank browser-window in addition to adobe file(opened in adobe not in browser)
<html>
<script type="text/javascript">
function windoeOpen() {
var myWindow = window.open(" ", "windowname", "width=200, height=100");
myWindow.location.href = "file:///F:/pdf2.pdf";
}
</script>
<body onload="windoeOpen()">
<code>
........
</code>
</body>
</html>
please give me suggestion how can I close the additional browser blank window.
Note:
but if I open pdf in browser ,it works fine(opened in browser as expected) no addition blank browser.
You just need to specify window.location.href like this:
JavaScript:
<script type="text/javascript">
function windoeOpen()
{
window.location.href = "file:///F:/pdf2.pdf";
}
</script>
HTML:
<body onload ="windoeOpen()">

window.location.href is not working from popup

I wanted to open the link from the popup window in same window and then close the popup window.
I got this which was similar to what I was looking for: open the link from the popup window in an external window and then close the original popup window
I tried the solution of that and its closing the popup which I wanted but not redirecting to the specified url.
I have PHP page e.g Page A in which I have used popup window as I mentioned in loading php page with class in javascript
now, on correct.php which opens in popup window, I have a button. For that I used the solution as below which is not redirecting to url :
<input type="button" value="Search" ONCLICK="window.location.href='https://www.google.co.in/';parent.$.colorbox.close();">
what may be the reason for not opening the specified url?
just create two php page user.php and user_admin.php. Copy and paste the code . first run user_admin.php . it will opens user.php using script . after user.php code runs . pop up window will close. function closeBrowser(){ self.close(); } this is script to close pop up window
user_admin.php
<html><head>
</head>
<body onLoad="clickButton()">
<script>
var pop = new Array();
function myFunction() {
pop[0] = window.open("http://user.php");
pop[1] = window.close();
}
</script>
<script>
function clickButton()
{
document.getElementById('button1').click();
}
</script>
<input type="button" id="button1" onClick="myFunction()" value="Button 1" />
</body>
</html>
user.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function closeBrowser(){
self.close();
}
</script>
</head>
<body onLoad="closeBrowser();">
<!-- Write your code here -->
</body>
</html>
I Hope this will help you . Try it once .

Javascript Open New Window And Write Content Again

I wrote a script in which when I press button first time, the window opens and contents are written. But second time I click on button, windows is focus instead of written content again.
Any Idea how to get rid of this?
<script type="text/javascript">
var OpenWindow;
function openwin(url) {
OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
OpenWindow.document.write("<meta http-equiv=\"refresh\" content=\"2;url="+url+"\">");
OpenWindow.document.close();
self.name="main"
}
</script>
<button onclick="openwin('http://www.google.com/')">Open Window</button>
I think this does what you want:
<script type="text/javascript">
function openwin(url) {
OpenWindow=window.open(url,"main", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
}
</script>
<button onclick="openwin('http://www.google.com/')">Open Window</button>
Your main problem was setting the URL in the body, instead of using the proper method of setting it in the open().

Categories

Resources