can a web page be manipulated through ajax from new window? - php

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.

Related

close modal after submit of form on redirect to same page

I have a form inside a modal that automatically opens on load. the form submits the time to a database when it is activated which starts a timer to evaluate how long it takes a participant to complete a task on the page. The page redirects to itself when the submit button is clicked as the events to be measured are on the opening screen. However when the page is reloaded the modal opens once again. How would I stop the modal from opening again on the submit of the form and reloading of the page? I have everything working but this part. I am using basic jquery. Nothing fancy.
Add destination url for your link. Get more help from below urls:
https://drupal.stackexchange.com/questions/66707/how-to-redirect-to-another-page-after-submitting-the-ctools-modal-form/108040#108040
https://drupal.stackexchange.com/questions/29157/redirect-form-out-of-modal-window-after-submit/108039#108039
You could redirect to the same page with an added query string value that stops the modal from being displayed.

How to send data from popup to parent window

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

Popup window with different contents

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

Running jQuery command from modal window to affect main page

I'm currently trying to write a jQuery script which opens a modal box then (upon user entry) changes a value on the original page.
Currently I've got the script working on just the page itself (without the modal), but when I try to run the command from the modal the value on the main page doesn't change?
Does anyone know how I can solve this?
Thanks,
Tom
Make a function in the page itself (not the modal sub-page), then call opener.myMethod() in the modal sub-page.
If the modal dialog is using an iframe, then from within the iframe you can do either of the following (depending on whether you have nested iframes or whatnot).
window.parent.myMethod();
top.myMethod();
And to access elements on the main page you could do this (assuming you have jquery included on the main page as well):
top.$('#myDiv').html('hello world');
Hope this helps.

posting variables between windows in php

my title may not be clear. But basically what I want to do is:
There will be a link in my php form
<a href="somepage.php" target=_blank>Update</a>
when the user clicks on the link, a new browser window opens and allows him to select some options. There will be close button in that window. When he clicks on that 'close' button, there is a post form from where the parent window should get the selected value.
When I get that selected value from that child browser window, how I am going to refresh parent browser window to reflect what user has selected in child window?
Environment : PHP
Can anyone give me some idea?
As far as I know you can't refresh a parent window using PHP (or, more correctly, pure HTML). You will need a bit of Javascript in your onLoad event:
window.opener.location.reload(); // Refresh
- or -
window.opener.location.href = "targetpage.php"; // Redirect
You would be able to refresh a child window that was opened before from that page using a named target:
<a href="new_window.php" target="my_new_window_i'm_going_to_refresh">
(apostrphe for demonstration purposes only :)
repeated clicking on that link should refresh the child every time. It doesn't work the other way round, though.
In parent expect the refreshed values something like as:
parent.php?value=xxx
on popup, when user clicks close, you can always use window.opener.location = "parent.php?value=XXX" ... this will refresh the parent with the value selected.

Categories