Javascript return value from popup as variable in function without input field

I know this question looks like previous questions, but it is a little different.

I want to write a function in my javascript like

this.imagePopup = function() { window.open("images/index.php","imageSelect"); //some code I don't know.... return imgUrl; }; 

What code do I need so that the URL of the selected image from the pop-up set in the imgUrl variable does not set a value in the text input field?

+4
source share
2 answers

You can write a javascript handler in the popup menu to call the method in the opener. For example, a handler method like this might help you:

 function onSelectedIndexChange(ddl) { if(opener && ddl) opener.selectImageInPopup = ddl.options[ddl.selectedIndex].value; } .. <select onchange="onSelectedIndexChange(this)">... 

Where selectImageInPopup is a global variable in the window that opens.

+2
source

Firstly:

 var myWindow = window.open("images/index.php","imageSelect"); 

Reset Images:

 console.log(myWindow.document.images); 

Find the position of the desired single image, for example (first image in a popup)

 var imgUrl = myWindow.document.images[0].src 

Good luck

0
source

Source: https://habr.com/ru/post/1442796/


All Articles