Avatar of moconn
moconn
 asked on

Help with Remote Control Window - 500 pts


Hi Experts,

I am having a problem with javascript remote control..

I have found loads of examples on the web of how to create a remote control to redirect the parent window to a new page
but nothing that does what i need..

Issue:

I have a form (parent window) and a popup (child window). When the popup is opened the user can upload an image I want to populate the path to the image into the relevant field in my parent window when the user closes the child window.

I.e.

Parent Window

Photo:

The photo below is the current photo
xxxxxxxxxxx
xxPHOTOxx
xxxxxxxxxxx
xxxxxxxxxxx

Change Photo   <----- Opens popup


Popup
 ______________________
|_____________________|

Browse | Upload

I.e. Once i've uploaded the file in the popup and its been previewed then the user closes the window
and the the path is passed back to the original window | original window refreshed so the user can see the photo.

PS The upload code is working fine, all i need is to be able to pass the url of the photo back to the original page and refresh the original page.

Thanks

JavaScript

Avatar of undefined
Last Comment
Zvonko

8/22/2022 - Mon
Zvonko

The popup can get this access to parent window:
<script>
function setParent(){
  var pImg = opener.document.images;
  var pForm = opener.document.forms[0];
  // now you can set the parent image src by the parent image name:

  pImg.PHOTO.src = "images/theUploaded.jpg";  // img.src
  pForm.imagePath.value = "images/theUploaded.jpg";  // form field value
}

window.onunload = setParent;

</script>



moconn

ASKER

Cheers for your answer,

Just want to clarify a couple of things excuse my complete novice at Javascript..

Currently i'm opening the popup in the parent by using this script between the <head> tag

<SCRIPT LANGUAGE="javascript">
<!--
var newwindow;
function poptastic(url)
{
      newwindow=window.open(url,'name','height=270,width=300');
      if (window.focus) {newwindow.focus()}
}
-->
</SCRIPT>

and this link in within the <body> tag

echo "<a href='javascript:poptastic(\"./upload_photo.php?article_id=$article_id\");'> Change Photo</a><br>";

Questions are:

a. I presume the code above is to be placed within the <head> tag of the popup?
b. Is my popup code in the parent combatible with your code above?
c. How is the updated path [images/theUploaded.jpg] accessible in the parent?
d. Does this code refresh the original parent window?

Thanks...




ASKER CERTIFIED SOLUTION
Zvonko

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
moconn

ASKER

That did the trick..

Thanks for all your help..
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Zvonko

You are welcome.