-1

I want to open - https://myUI:88/openURL/ (e.g.: On click of a button, it should redirect to this https://myUI:88/openURL, like it happens in payment gateway) and then, I have to pass the below user script to that:

getRealData('{"mailing":{"postalCode":"111","city":"NJ"},"terminal":"222"}');

How to achieve this in AJS 1.x?

getRealData is a public method in https://myUI:88/openURL web app

3
  • Pass the "user script" in the sense?? Do you want to send the json data to the opened window from your main window? Commented Jan 31, 2017 at 10:29
  • Yes.. and call the method - getRealData on that url (its a web app) Commented Jan 31, 2017 at 11:15
  • Is it possible to do something with data uri? developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/… Commented Feb 1, 2017 at 9:17

1 Answer 1

0

You can pass data between parent window and child window by using the window.postMessage() API.

In Parent js file :

var childWindow = window.open(childurl);// opens a new window and puts the reference to it in childWindow variable.

childWindow.postMessage(YourMessageJson);//the json should be stringified before sending

In child's js file :

window.addEventListener('message', receivedMessage);//attach event listener to get the event sent by postMessage from your parent.

function receivedMessage(data){ //callback function executed on receiving the message
  xhr.open(url) //The http call that you wanted to make from this page (I have just put a dummy xhr call, replace it according to your use case)

}
Sign up to request clarification or add additional context in comments.

7 Comments

This looks good, but I have no control on my childUrl and its an existing legacy web app, which has this function - getRealData
You WILL not be able to call a function existing in another app without writing some code to handle the event you pass from your app. And it is also a very bad practice as it involves cross-site scripting and makes the app very vulnerable.
Is it possible to run any user script for it and make it run via tampermonkey etc, compromising security tempororily is fine for now
Nope not possible.. tamper monkey doesnot allow invoking functions on other script.
Can i run a new user script - getRealData('{"mailing":{"postalCode":"111","city":"NJ"},"terminal":"222"}'); on tampermonkey and do a window.open()? Also, currently pay = null (not sure , why, window.open returns null, even though a new window is opened)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.