Close popup window opened by a different domain - javascript

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

Related

How to close the webpage on its own on clicking a button

I have a page where a <button> is kept on which onClick() event fires and redirects the new page in new tab. Meanwhile I want the parent page to close itself as soon as the <button> is clicked with opening the new page in new tab. Its basically for some security feature for the website. How can this be done?
Here is my <button>, let me know where can i correct myself.
<button formtarget="_blank" type="submit" name="submit" onClick="javascript:window.open('quiz.php?unit_id=<?php echo $fnc->encode($unit_id) ; ?>');self.close();" value="submit" class="btn btn-info" style='margin-left: 35%;margin-bottom: 10px;' ><i class="glyphicon"></i> Start Quiz</button>
you can close window by below function
function close(){
setTimeout("window.close()", 500);
}
But keep in mind that : Scripts may close only the windows that were opened by it.
The window close and open new tab
<script language="javascript">
function quitWindow(cmd)
{
if(window.open("your_new_tab_page.htm")){
if (cmd=='quit')
{
open(location, '_self').close();
}
}
return false;
}
</script>
<input type="submit" onclick="return quitWindow('quit');" value="Close This Window and open new Tab" />
If you use firefox, you should about:config by writing url bar and set
dom.allow_scripts_to_close_windows = true
otherwise does not work firefox
I think this might work.
<script>
function openWindow( url )
{
window.open(url, '_blank');
window.focus();
window.close();
}
</script>
<button onclick="javascript:openWindow(yourHref);return false;">Submit</button>
You cant close your webpage if the user clicked the link of your website from any other place other than your website, due to security reasons.

Pass parameters to popup window from button - MVC

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>

Self exit button

I got my page to open with JS, with
<a href="javascript:openNewWindow();">
Now, the webpage will open in _self. I need to find a way to get a link, that will close my window. This doesnt work:
<a href="javascript:window.close();">
Now what to do? Anyone knows a better way to close self window? The second script has to be in the opened page.
This is a correction of my previous answer:
newwindow=window.open();
newdocument=newwindow.document;
newdocument.write("Hello World.<input type='button' value='close' onclick='window.close()' />");
newdocument.close();
as you can see, window.close() works ok.
For a specific example, you can use this -> create 2 files:
1. windowOpener.html
<html>
<body>
<input type="button" value="open" onclick="window.open('newWindow.html')" />
</body>
</html>
2. newWindow.html
<html>
<body>
<input type="button" value="close" onclick="window.close()" />
</body>
</html>
if you'll run windowOpener.html and click 'open' it will open 'newWindow.html'. clicking 'close' in the new opened window, will close it. voila.

Using JavaScript to launch window behind browser for users agreeing to survey

I am asking a small percentage of users on a site if they would take a short survey. If they click 'yes' I would like to close the little pop-up window i have open that is asking them, and launch a new window in the background that comes to the forefront once they leave my domain - or close their browser.
Right now I am using a form:
<form>
<input type="button" value="Yes" name="Yes" onclick="javascript:openSurvey();">
<input type="button" value="No Thanks" name="No" onclick="javascript:closeSurvey();">
</form>
I'm having trouble with this though. I think I can launch the new window OK, but I can't figure out how to close the other window and put the new window in the background. Any tips?
put the following code in the new window:
window.onload = function()
{
self.blur();
};

Close a bookmarklet after submitting form

This is related to question "Bookmarklet behind elements".
I want to either self close the iframe after form submission or if not possible, add a close button with the iframe to close it. my bookmarklet at the moment is
javascript:(function(){var iFrame=document.createElement('IFRAME');iFrame.src='http://www.yeongbing.com/testform/dd-formmailer/dd-formmailer.php';iFrame.style.cssText='display:block;position:absolute;top:5%;left:60%;width:40%;height:51%;overflow:hidden;';document.body.insertBefore(iFrame,document.body.firstChild);})();
I have tried the methods mentioned here but can't seem to work. Any suggestions?
Here's how you can close the iframe from your "Close Window" button.
First, give your iframe an id by adding "iFrame.id='foo';" to the end of your bookmarklet script:
javascript:(function(){var iFrame=document.createElement('IFRAME');iFrame.src='test2.html';iFrame.style.cssText='display:block;position:absolute;top:5%;left:60%;width:40%;height:51%;overflow:hidden;';document.body.insertBefore(iFrame,document.body.firstChild);iFrame.id='foo';})();
Then, in your iframe's source, change
<input type="button" onclick=window.close() value="Close Window"/>
to
<input type="button" onclick="parent.document.body.removeChild(parent.document.getElementById('foo'));" value="Close Window"/>

Categories

Resources