How to call a jsp page in a popup from JS - javascript

I tried with windows.location but it opening in new tab. But i want to open it as pop up. I tried with:
function update(expenseId){
alert("test" + expenseId);
window.location.href("/jsp/user.jsp","height=400,width=400");
}
but this also throwing window.location.href not a function error. please help with this.

You can change or adop it to your function
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var myWindow = window.open("/jsp/user.jsp", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
}
</script>

Try this
function update(expenseId){
alert("test"+expenseId);
popup_window = window.open("/jsp/user.jsp","height=400,width=400");
popup_window.focus();
}

Related

How to close printing window

I want to close the window which has printing dialog on that using window.close() function.
I realize that, if the window does not have printing dialog, the window.close() function will works fine.
Here is the example code:
<button onclick="openWin()">Open "myWindow"</button>
<button onclick="closeWin()">Close "myWindow"</button>
<script>
var myWindow;
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
}
function closeWin() {
myWindow.close();
}
</script>
But if I put the print() function into the above code, I will not be albe to click the close window button until the printing dialog is closed.
Here is the example code
<button onclick="openWin()">Open "myWindow"</button>
<button onclick="closeWin()">Close "myWindow"</button>
<script>
var myWindow;
function openWin() {
myWindow = window.open("", "myWindow", "width=200,height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
myWindow.print();
}
myWindow.print() {
myWindow.close();
}
I want to know why does that happen and how can I close the window which contains printing dialog.
Thank you.
Instead of doing mywindow.print() myWindow.close(); separately to the function, put myWindow.close() inside the function then just call that. It seems weird that you're doing myWindow.print() and closing inside of that, I dont think that'd work.

Printing Popup Window after loading

I've spent more than 5 hours on this, I'm trying to load a link on a popup window and after loading I want to print it.
so what I did is the following
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
function printer(){
var link = 'file:///C:\\page0339.swf';
w = window.open(link, "_blank", "location=1,scrollbars=1,menuBar=1,width=600, height=400");
w.onload = function() {
this.print();
this.close();
};
}
$(document).ready(function () {
$("#print").click(function () {
printer();
});
});
</script>
<input type ="button" id = "print" value = 'print' />
inside onload I've tried alert message and it shows up but both this.print();this.close(); are never called, and I didn't see any javascript error.
so How I can call print function inside onload??
Seems like attaching an onload after already opening the window is the wrong way to go. Instead of
w.onload = function() {
this.print();
this.close();
};
Have you tried this?
w.print();
w.close();

resizeBy not working and don't know why

Why doesn't my resize button resize the window that my "create window" -button creates? I have searched and none of the answers I've found work. I'm all out of ideas now. Please help!
<div id="windowbuttons">
<button onclick="openWin()">Create window</button>
<button onclick="resizeWin()">Resize window</button>
<script>
var myWindow;
function openWin()
{
myWindow = window.open("http://www.google.com","", "width=100,height=100");
}
function resizeWin()
{
myWindow.resizeBy(250,250);
myWindow.focus();
}
</script>
</div>
And it does work correctly when I delete the url from window.open, so that it looks like
function openWin()
{
myWindow = window.open("","", "width=100,height=100");
}
What is going on?
var myWindow;
function openWin()
{
myWindow = window.open("http://localhost","", "width=100,height=100");
}
function resizeWin()
{
myWindow.resizeBy(250,250);
myWindow.focus();
}
<div id="windowbuttons">
<button onclick="openWin()">Create window</button>
<button onclick="resizeWin()">Resize window</button>
</div>
You are opening http://google.com in a new window and then you are trying to resize http://google.com from your script, which is restricted. In order to work this, your child window must reside on the same host and port as of your parent window

How to close a popup window in javascript that was sent to the background

So I was trying to use the window.close method, but it doesn't seem to be working. Here's the code:
<script>
var popup;
function openPandora() {
popup = window.open('http://www.pandora.com', '', 'width=100, height=100, resizable=no');
popup.blur();
document.getElementById('container').focus();
}
function closeWindow() {
popup.close();
}
</script>
The HTML just calls <a> with an onClick="closeWindow();"
Any ideas on how to get that popup to close? Thanks!
Are you sure if closeWindow() is getting called.
Try this
function closeWindow() {
alert("Going to close popup");
alert(popup);
popup.close();
}
What do you see?
It seems to be working for me with your code.
Try here:
http://jsfiddle.net/zfSWX/
This is my working code ---
<!DOCTYPE html>
<html>
<head>
<title>For Alex</title>
<script>
var popup;
function openPandora() {
popup = window.open('http://www.pandora.com', '', 'width=100, height=100, resizable=no');
popup.blur();
document.getElementById('container').focus();
}
function closeWindow() {
popup.close();
}
</script>
</head>
<body>
<button id="add-friend" onClick="openPandora()">Add Friend</button>
<ul id="friends-list">
</ul>
dfd
</body>
</html>

Open popup and refresh parent page on close popup

I opened a popup window by window.open in JavaScript, I want to refresh parent page when I close this popup window.(onclose event?) how can I do that?
window.open("foo.html","windowName", "width=200,height=200,scrollbars=no");
You can access parent window using 'window.opener', so, write something like the following in the child window:
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>
The pop-up window does not have any close event that you can listen to.
On the other hand, there is a closed property that is set to true when the window gets closed.
You can set a timer to check that closed property and do it like this:
var win = window.open('foo.html', 'windowName',"width=200,height=200,scrollbars=no");
var timer = setInterval(function() {
if(win.closed) {
clearInterval(timer);
alert('closed');
}
}, 1000);
See this working Fiddle example!
on your child page, put these:
<script type="text/javascript">
function refreshAndClose() {
window.opener.location.reload(true);
window.close();
}
</script>
and
<body onbeforeunload="refreshAndClose();">
but as a good UI design, you should use a Close button because it's more user friendly. see code below.
<script type="text/javascript">
$(document).ready(function () {
$('#btn').click(function () {
window.opener.location.reload(true);
window.close();
});
});
</script>
<input type='button' id='btn' value='Close' />
I use this:
<script language='javascript'>
var t;
function doLoad() {
t = setTimeout("window.close()",1000);
}
</script>
<script type="text/javascript">
function refreshAndClose() {
window.opener.location.reload(true);
window.close();
}
</script>
<body onbeforeunload="refreshAndClose();" onLoad='doLoad()''>
when the window closes it then refreshes the parent window.
window.open will return a reference to the newly created window, provided the URL opened complies with Same Origin Policy.
This should work:
function windowClose() {
window.location.reload();
}
var foo = window.open("foo.html","windowName", "width=200,height=200,scrollbars=no");
foo.onbeforeunload= windowClose;​
In my case I opened a pop up window on click on linkbutton in parent page.
To refresh parent on closing child using
window.opener.location.reload();
in child window caused re open the child window (Might be because of View State I guess. Correct me If I m wrong).
So I decided not to reload page in parent and load the the page again assigning same url to it.
To avoid popup opening again after closing pop up window this might help,
window.onunload = function(){
window.opener.location = window.opener.location;};
If your app runs on an HTML5 enabled browser. You can use postMessage. The example given there is quite similar to yours.
Try this
self.opener.location.reload();
Open the parent of a current window and reload the location.
You can reach main page with parent command (parent is the window) after the step you can make everything...
function funcx() {
var result = confirm('bla bla bla.!');
if(result)
//parent.location.assign("http://localhost:58250/Ekocc/" + document.getElementById('hdnLink').value + "");
parent.location.assign("http://blabla.com/" + document.getElementById('hdnLink').value + "");
}
You can use the below code in the parent page.
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>
Following code will manage to refresh parent window post close :
function ManageQB_PopUp() {
$(document).ready(function () {
window.close();
});
window.onunload = function () {
var win = window.opener;
if (!win.closed) {
window.opener.location.reload();
}
};
}

Categories

Resources