Window Closing Issues In Ajax - php

In codeigniter application i pop up a window from a view page using href link.In that pop up window there have a button to close window after done process.
I want to refresh the view page after closing the pop up window when i clicking on the button in the pop up window.How can i do that?Is there any way to solve my issue

Have the close button call this javascript:
if ( window.opener && !window.opener.closed ) {
window.opener.location.reload();
}
This will test that the opening window exists and is not closed, and then try to reload it.
You could also access other functions or variables using window.opener if you wanted to call some other function, or make it a little more dynamic by only changing one part of the page.

Related

Reload parent page from PHP page loaded in DIV tag

Hi I have a PHP page loading in a DIV tag from a javascript function. I also have a button on this PHP page that sends information to another PHP page. I was using header to go back to the page I was on (still in the div tag) but I was wondering if there is a way to reload the original parent page. The pages are all saved in separate files so I was unsure how to do this. I have tried using Javascript such as top, window, and opener for location.reload() e.g.
top.location.reload()
window.location.reload()
and saving the function on each page as
function myFunctio(){
location.reload();
} and then calling it on each page again using top, window, and opener but nothing has worked. If I use a header it will only load the page in the DIV.
You can use them in sequence to get the result you're looking for give something like window.opener.location.reload(false); a try

How to close a pop up window using the anchor's OnClick in javascript?

I have a php page that opens a pop window. it contains the search results. each result is inside the anchor tags.
I can open a new tab containing the information in the parent window, but somehow the OnClick function does not work. what i want to do is when the user select a link, will open a new tab then the pop up window automatically close. I dont know why the OnClick event is not doing what I want.
<?php
<a href='edit.php?id=$id' target='_blank' onClick='self.close();'>Listq</a>
?>
the code above works but it closes the pop up before opening the new tab. please help. thanks.
Try to close the popup from the new tab on load and not from the popup:
window.opener.close();
Try this:
onClick='setTimeout("self.close();",1)'
Check out this
Close
function closeWin()
{
self.close();
}
You can try onmouseup in stead of onclick. And if that fails too you can also do the opening of the popup in the onclick with window.open(). That way your order is maintained.
So it would look like:
Listq
And get writ of the <?php and ?> tag, or put the anchor in an echo if this is PHP.

open links in new window from sub window or Ajax

I need your quick help.
In my web site I have a list of clients with links to their user details.
I used
window.open();return false;
and this opens each profile in new window.
now in the new opening window I have link, which I want to open in another new window/
I tried
window.opener.open();return false;
but it opened in this same window.
How can it be opened in another new window(FF,explorer)??.
I want also to use the above code with Ajax, in my search page.
The problem is, that it also not opening the new window because the link located in the Ajax. how can i open links from Ajax in new window??
Any ideas?
Thanks!!!
Well you can access window.parent from your window object and call a function that will open another window
Use Window.open() in the opened window.
So you have : (1) Page with a link -> (2) opens a popup with a link -> (3) opens another popup
Every link which has to open a popup will call the javascript function window.open. As #Sushil pointed out, if the new window has to look like a regular popup, set width and height to it.
If you want to implement the popups using AJax, use jQuery. Here is a very good example for a simple popup implementation.
Providing height and width to open. this will make sure that new window always open as popup.
window.open(url, 'name', "height=500,width=700"); return false;

Facebook like button not displaying after refreshing a div by using load();

I'm using a simple script to reload a div
$('#mydiv').fadeOut('300').load('# #mydiv').fadeIn("300");
The problem is that the div I'm reloading has the Facebook like button inside it. After the DIV reloads, I can see it updated inside the source, but the button is hidden for some reason.
Is there any way to force the button to re-draw?
As I stated in my comment, I think the .load is misunderstood, as you stated in your question
I can see it updated inside the source, but the button is hidden for some reason
.. so with that in mind, I assume you have load functioning with the correct parameters.
You have a synchronistic problem here. Everything you use in the chain uses a timescale, and .load() for that matter is asynchronous.
So instead of just chaining everything, you have to use the callbacks in order to know when the time scale ends for a particular function.
$('#myDiv').fadeIn('300', function() {
// callback when #myDiv is faded out (display:none;)
$(this).load('url', function() {
// callback when #myDiv is loaded with new content from the given 'url'
$(this).fadeIn('300');
})
});
The facebook button won't display because it is configured normally just AFTER document.load.
If you load the div content while the document is already loaded and the Facebook javascript SDK has already initialized. It won't work.
If facebook is not required UNTIL the div loads. You may just try to load the "all.js" script inside the div.
Otherwise, if you've come to that, you'll certainly have to review the application's design.

Show popup when the browser closes

popup when the browser closes
I am using onbeforeunload event
<script>
function showPopup()
{
urlstring = "http://www.mydomain.com/popup.php";
window.open(urlstring,'mywin',"height=400px,width=500px,status=no,toolbar=no");
}
</script>
<body onbeforeunload="showPopup(); ">
but it also show popup when ever I hit back space and page refresh.
I want show popup only when browser close and not show when hit back space.
but it shows all conditions.
Please suggest me any other solution for this.
This is showing a popup every time because the onbeforeunload event is not aware of the domain you are leaving, it is only aware of the current page unloading for a new one.
Well , here's the bitter truth...
onbeforeunload is fired on page refresh and browser close.
The onbeforeunload event is fired every time the page is about to unload.
Which includes
Clicking on a link
Submitting a form
Closing the browser(or tab)
Refreshing the page
You might find this helpful
http://www.webdeveloper.com/forum/archive/index.php/t-36808.html
<script>
function showPopup(){
urlstring = "http://www.mydomain.com/popup.php";
window.open(urlstring,'mywin',"height=400px,width=500px,status=no,toolbar=no");
}
window.onunload= showPopup();
</script>
Note: This is DOM Level 0. Not part of any standard
EDITED: Note Infotekka's link to the document.onunload will also work appropriately for this problem.
You can't.
Your page, including its events, is not aware of other tabs, other pages or the browser itself for that matter. It also doesn't know why it is unloaded. The onunload event is the closest you will get, but it fired everytime when your page is unloaded, so also on navigation.

Categories