I want to open a popup on pageload .In this popup people can fill data in dropdown for city and locality.
After closing this popup this data should be sent to my parent window where I have a form which contain city and locality textbox.
No I want to implement this using php and javascript.pls suggest.
Put this echo code at php end of child window,
echo '<script type="text/javascript">
window.opener.function_name_of_parent_window('.json_encode($user_data).');
window.close();
</script>';
That will call your desired function on parent window and data that you want to send over there as parameter
I would suggest modal windows (because now browsers block onload popups) and ajax. PHP here is not required, as everything can be implemented in client side
You should with javascript be able to set a variable on the parent page using:
parent.data = localdata
however, why do you want to use a popup window in the first place. A popup layer would be much cleaner and wouldn't be blocked by popup blockers
Related
I have some buttons containing different contents and when the user clicks, a new window should popup with the content for the clicked button.
There should only be one popup window where the content should be altered, depending on which button the user has pressed.
I'm using PHP to generate HTML code but I can't find a way to do it as PHP is server side..
Don't want to use href in html, JS could work, although I'm not great at JS..
Here is a site that will auto-generate javascript code for a popup window that you can attach to your buttons
Hi... I want to know that when a user posts a comment to my site ... to open a web page (in new window, with a fixed width and height like window.open ) which contains the form and after submit, I want to close that windows and show that comment in the parent page through ajax ... (or i guess after closing that window, to auto reload the parent page ... I don't know ) ...
Is there any solution to this .. ?
Or what is the best way to open a pop-up which contains the form (not a new window) ?
Thank you very much.
Attach an onclick handler on whatever you use to let the user make a comment
This handler pops up the new window with the form
The form submits the comment to the server via ajax
Once the ajax handler is done on the server, it returns the comment's ID to the form window script
the form window script calls a function in the original window, passing in the comment ID, telling the window to load up the new comment (via another AJAX call, or directly passing the comment details from the form page)
the form page script then closes the window.
on the popup window form tag add target="_PARENT"
on the popup window change the submit button to normal button.
on the popup window, when button clicked, submit the form with js and close the window.
document.formname.submit();
this.close();
in this case your popup window is just to get data then the data will be posted to the main window...
You can access the parent window by using the window.opener JavaScript property. More info here
Does it have to be a new window? Why not a modal form? Take a look at this basic jQuery modal form.
How to get informed if your PopUp window was blocked BY pop up blocker? (CODE EXAMPLE NEEDED)
With
window.open (URL, windowName[, windowFeatures]);
you open a new popup and as URL you put some html page. In that popup'ed page you write some JS in which you can use window.opener variable so you can has an access to all JS from your main page.
Then you can in popuped page set some flag - for example:
index.html
<html>
<body>
<script type="text/javascript">
var opened = false;
window.open('popup.html');
// and here some loop in mooTools/jQuery/or
// something to look up for variable changes
</script>
</body>
</html>
popup.html
<html>
<body>
<script type="text/javascript">
window.opener.opened = true;
</script>
</body>
</html>
I'll do this that way.
Edit
And here is another way using PHP:
In your popup.php you can set some flag in session
$_SESSION['opened'] = true;
And in index.php you should write something to AJAX requesting to ana action which will returns you a value from $_SESSION.
The short answer is that you can't unless you really want to punish your users.
Popups are typically generated on the client side using JavaScript, so therefore you cannot know if the popup was blocked from the server unless you are watching to compare requests for page content versus requests for popup contents from the same IP. That method produces an incredible number of false-positives and false-negatives though because if a user refreshes the page they may not get the popup a second time, but they may have gotten it the first time. Or a popup window could have generated and content in that window can then load independently of content in the rest of the page. As a result the only rational solution is entirely unreliable.
So, what you can do is write a JavaScript test to measure if a popup window generated as it should have from the firing JavaScript. When the firing JavaScript fires, but the popup window does not immediately exist then you would have to fire off AJAX to send you an alert so that you are dynamically notified the popup failed to load. If I ever saw code like this, however, I would blacklist your entire domain from my enterprise and alert major security firms that you are either a malicious website or have been compromised.
I have this at above the body tag in my page --
<script type="text/javascript">
$(document).ready(function() {
$('#button').popupWindow({windowURL:'http://something',centerBrowser:1,width:400,height:300});
});
</script>
Is there a way to make this popup happen without the user actually clicking a button -- programmatically w/ code inserted into the middle of the page with php on page load?
Add the following next.
$("#button").trigger("click");
Or put it all on on chained line:
$('#button').popupWindow({...options...}).trigger("click");
For what it's worth, you can invoke this from a non-rendered element:
$("<div></div>").popupWindow({..options..}).click();
I think for security reasons a lot of browsers will not open a popup window without some kind of user action.
popupWindow is hard-coded to work with links, and only responds to "click" events. That said, if you want the popup to appear on page load, you could try editing line 6 of jquery.popupWindow from this;
$(this).click(function(){
to this;
$(this).ready(function(){
add an id to your body element;
<body id="popuptrigger">
and call the plugin;
$('body#popuptrigger').popupWindow({ ... });
This is untested, but even if it works it's not a very elegant solution. I'd suggest looking around for a popup plugin that allows you more flexibility. I use jqModal to load internal url requests for popup forms and can throughly recommend it. Your mileage mey vary though, so do a google search for "jquery modal" and check out some alternatives.
I'd suggest using a jQuery UI Dialog. That way you won't have to worry about how different browsers handle popups differently.
As stated by others, some browsers (notably Microsoft Internet Explorer) will refuse to open a JavaScript popup window unless it was triggered as a result of user interaction. You can easily fake this with a bit of jQuery:
// Create a 'fake' a tag, this will never be added to DOM.
$('<a href="#" />')
// Register a click handler which will open a new popup window.
.click(function () {
window.open(url, name, options);
})
// Simulate the click in jQuery - this will open the popup window.
.click();
I can't comment on the accepted solution, so I'll just post this here - regarding Jonathan Sampsons last proposition (which is really clever): on latest Firefox & Chrome the element, that triggers the click event, must be visible. So you can't really generated a non-rendered element.
Also, if you're using an element from your page, just choose one that doesn't have any other click event defined yet - otherwise all other click events will trigger, which might not be the desired outcome.
I want to open a popup window on client PC where I will show records. The user will click on the selected row, and the popup window will disappear, but the parent Form on my page must get filled with the DB values related to the clicked row on the popup.
This is what I want to do. What is the right approach?
You should be able to send back some response to your parent window from popup window.
There is a specific javascript methods to do this. See this.
You can also use a modal popup type container which will make communication simpler and give you more control of the data. It'll also work flawlessly even if the client has any sort of popup blocker (which most do by default).
It's easy to build from scratch and there are also many jquery plugins that make it even simpler.