Pass parameters to popup window from button - MVC - javascript

I have a button in my view that creates a pop-up window but I am not sure how to pass parameters back to the controller which will be running in the pop-up window.
I have looked at many methods of new pop-up windows but I need to be able to change the size of the window so I dont think target="_blank" will work.
Below is the code I am using to open the new window, can someone please suggest how to pass parameters to the uploadFeedback controller please.
<input type="button" id="btnpopu" value="Upload" onclick="ShowPopup();" />
<script type="text/javascript">
ShowPopup = function () {
window.open('/ViewAssignment/UploadFeedback', "PopupWindow", 'width=400px,height=400px,top=150,left=250');
}
</script>

Related

populate values from parent window in pop up using javascript

I have a jsp page with a link.
View
When the link is clicked PopUp.jsp opens in another window.
I would like to populate this window with values from the first jsp.
Example:
Parent.jsp
<input type="text" id="name"/>
<input type="text" id="city"/>
View
PopUp.jsp
<script>
function setThis(){
document.getElementById("pname").value=document.getElementById("name").value;
document.getElementById("pcity").value=document.getElementById("city").value;
}
</script>
<body onload="setThis();">
<input type="text" id="pname"/>
<input type="text" id="pcity"/>
</body>
I can't figure out why it doesn't work. Is there a problem with my code?
You can use window.open method and use the object returned by that to access the new window instance. The returned object can be used to access properties and methods of the new window provided it complies with Same origin policy security requirements.
Assuming you have jQuery loaded to your page (If not,you can use vanilla javascript to wire up your click event to your code. use onclick event)
$(function(){
$("#popUp").click(function(e){
e.preventDefault();
var url="url to the new page here";
var newWindow = window.open(url);
var pname="read from this page";
var pcity="read from this page";
newWindow.setThis(pname,pcity);
});
});
Update your setThis to accept these values
function setThis(pname,pcity)
{
.// do something
}

window.close() not working on pop up with pop up

I have a Customer Info form that has anchor tag "close" that should close the current window. This customer form is being opened as pop up. The Customer form also has a search btn that when clicked it pop ups the search form that is being run by a javascript called searchOrder.js. So basically it is a pop up inside a pop up. The customer form's close btn is not working but when the reference to searchOrder.js is removed, it begins to work. Also, when the search pop up is open and I click the "close" anchor tag, it closes the search pop up but never the current window which is the customer form.
Ive tried a lot of solutions already but nothing is working. I used self.close(), window.opener.close(), made it a btn instead of a link etc.,c alled a function onclick
function closeWindow() {
var closeRef;
window.opener='x';
closeRef = window.open('','_parent','');
//or closeRef = window.open("",name);
closeRef.close();
}
heres my gsp code:
<g:form method="post" name="CustomerInfoForm" target="_parent" role="form">
<div class="id="closeLink">Close</div>
<button id="searchOrderButton" type="button" class="button" onclick="searchOrder(document.forms[0].summaryMessage.value,'summaryMessageText','${createLink(action:'searchOrder')}','${createLinkTo(dir:'images',file:'closeButton.gif')}')" value="Search Order">Check Order</button>
</g:form>
How do I make the current window (customer info ) close? tnx
You should use a function like this to close your popup window :
<g:form method="post" name="CustomerInfoForm" target="_parent" role="form">
<div class="id="closeLink">
Close
</div>
<button id="searchOrderButton" type="button" class="button" onclick="searchOrder(document.forms[0].summaryMessage.value,'summaryMessageText','${createLink(action:'searchOrder')}','${createLinkTo(dir:'images',file:'closeButton.gif')}')" value="Search Order">Check Order</button>
</g:form>
<script type="text/javascript">
function openpopup()
{
my_window = window.open("","myPopup","status=1,width=100,height=100");
}
function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
}
</script>
EDIT : Don't forget to open your popup with the openpopup() function :
Open Popup Window
You can shorten window.close() to just close() and shorten window.open() to open(). Maybe you'll find what you need here, though:
http://www.w3schools.com/js/tryit.asp?filename=try_win_closed
http://www.w3schools.com/jsref/obj_window.asp

Close popup window opened by a different domain

I have a link in abc domain which opens a popup window and opens a page in a different domain. I need to add a button on the popup which calls window.close() and closes it via javascript. Is is even doable? can I close a popup using windo.close which has been opened by a different domain?
Do you mean something like this:
function openWin(){
myWindow=window.open("http://www.google.co.uk","","width=200,height=100");
}
function closeWin(){
if(myWindow){
myWindow.close();
}
}
hooked up to these buttons:
<input type="button" value="Open 'myWindow'" onclick="openWin()" />
<input type="button" value="Close 'myWindow'" onclick="closeWin()" />
it's a tad crude but should work... I'd also make it unobtrusive if I were you, I've used obtrusive code just to get an answer to you quickly

How to display a message in a pop up window

I have a pop up window function where when a button is clicked the window does pop up. Now the pop up window does not display anything, for a test I want the pop up window to display the word "Session". But I don't know how to do this.
Am I supposed to write the word "Session" in another page and link to that page or is it possible to write the word "Session" on the same page and link it to that section of the page?
I want the latter to happen but I don't know how to do it.
Below is my code:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Create a Session</title>
<script type="text/javascript">
function openSessionPopup (session) {
window.open(session,
'window',
'width=500,height=500,scrollbars=yes,status=no');
}
</script>
</head>
<body>
<form action="create_session.php" method="post" name="sessionform">
<p><input class="questionBtn" type="button" value="Prepare Questions" name="prequestion" onClick="openSessionPopup(this.href); return false" /></p>
</form>
</body>
Try something like this:
var win = window.open("about:blank", null, "width=400,height=300");
var doc = win.document;
doc.open("text/html");
doc.write("Session");
doc.close();
Try it on JSFiddle.
Alternatively, you can create a new page with the content you want and open that:
window.open("my-new-page.html", null, "width=400,height=300");
If you want to write the word session into the popup.. be sure to use " before and after since it's string... like this window.open("session", 'window', ...
" or ' will do the job either way.
Your popup typically displays another page when it appears. It is this other page that will have the content you want displayed.
This code would never work. When you pass in this.href, the this refers to the input element on which you've clicked. Input elements do not have an 'href' attribute, so you're passing in an undefined value.
You can pass the href as the argument for the "session" parameter. You see this works by putting this code into a file called "question.html" and testing out the button.
Replace the href with the page you want to display.
onClick="openSessionPopup('question.html'); return false"
First parameter in windows.open function is URL. So when you passed an empty value it opened the window with url about:blank (empty page).
If you want open url http://example.com/ in popup window you must use your function as:
openSessionPopup('http://example.com/');

How to close popup and redirect a page

My site using php and i create an online quiz and the quiz show in pop up mode.
Currently when i want to redirect my page using the script below. it goes to my homepage BUT it still at the pop up mode. I want it to close the pop up and go to homepage after I click finish.
How can I do that?
<script type="text/javascript">
window.parent.location = "../../../"
</script>
You can access the window that opened a popup with the window.opener property on the popup. So, something like this should work:
window.opener.location.replace(redirectUrl);
window.close;
If you wanted to put that behavior in the onclick event on a submit button you're building like this:
echo "<input type=\"submit\"
name=\"finishattempt\"
value=\"".get_string("finishattempt", "quiz")."\"
onclick=\"$onclick\" />\n";
You'd need to assign the String window.opener.location.href='someUrl';window.close(); to the variable $onclick before echoing the submit button out.
You can try this code (used on an HTML button):
<input type="button" onclick="parent.window.opener.location='http://homepage.com'; window.close();">
And have a look at some similar threads like this one: Javascript: Close Popup, Open New Window & Redirect
[EDIT] See this article too
this way you can do it ..
<script type="text/javascript">
function close_window(){
window.opener.location = 'pop_up.php';
window.close();
}
</script>
html code..
<body>
<form method="post" name="frm_2" id="frm_2">
<input type="submit" name="btn_close" id="btn_close" onclick="return close_window();" />
</form>
</body>

Categories

Resources