Javascript Target Window Losing Name - javascript

I am opening a link in a new window w/ a tampermonkey script when a certain page loads:
window.open("http://www.google.com/search?q="+searchText+"", "myWindow",false);
This opens a child window with the correct google results. Then when I reload the parent window, the same script runs. It should display the new results in the 'myWindow' child window, but it doesn't work.
Right now, it spawns a completely new child window on each parent window reload. The name of the new child window is no longer 'myWindow' after google returns the results. How can I fix this?

Related

Switching to a new window opened by a parent window that closes immediately

I'm new to selenium (new to java) and I'm having problems switching from one window to another.
the behavior of this IE system I am testing is once a button is clicked, it opens a new window and closes the old one immediately. Most of the guides I found on google involves multiple windows that are simultaneously open but this is not the case.
I have tried the following code:
String winhandlenew = driver.getWindowHandle();
driver.switchTo().window(winhandlenew);
by my understanding I don't need recursive codes as I don't have a parent window to switch back to (closes immediately after the new window is opened) so I just used a simple switchto command
the commands themselves do not give any error but as i progress, every element on that new window cannot be found. So, basically I have no clue if I'm switching correctly or if there is still a need to switch.
I would also like to note that both the parent window and child window have the same title.

How can I prevent child window changing parent window behavior?

I have a page with a link with opening attribute '_blank'. But when click the link and open a new window, there are scripts in the new window, like 'window.opener.location' which changes the parent window's behaviors. However, this is not I wanted. How can I prevent this happening.
Thanks.

window.close closes the postbacked child window and a copy of child window still appears

I am opening a child window using the below code:
window.showModalDialog("FileUpload.aspx", "FileUpload",
"center:yes;resizeable=yes;dialogHeight:300px;dialogWidth:600px;");
I save the file uploaded in the child window(FileUpload.aspx)in its code behind FileUpload.vb page.
Since server side code, its postbacking and opening a new browser .
After my functionality in the child window, when I close it using below code,
window.open('', '_self', '');
window.close();
it is closing the new browser opened because of postback but a copy of the same child window is still open when returning to the parent page.
I want to close all the instances of this child window.
The showModalDialog method will freeze JavaScript execution on the parent window until the dialog that it opens has closed, so we can rule out that as the reason why your second window opens. When FileUpload.aspx posts back from the server, it should work the same way as modeless aspx postbacks.
I think you should be able to get rid of the window.open() method and you should be fine.
Parent window:
window.showModalDialog("FileUpload.aspx", "FileUpload",
"center:yes;resizeable=yes;dialogHeight:300px;dialogWidth:600px;");
The Child window will call this when it's done.
window.close();

Open a completely new window with JavaScript without replacing the contents of the previous window

I have a page with several links that open a separate window with varying content. My goal is to open a window for each and every such link using JavaScript. My problem is as follows:
let's assume:
- i have two links on the page, lnkDoWorkOne and lnkDoWorkTwo
- lnkDoWorkOne opens a window with url = WorkOne.aspx which in turn does some work upon loading
- lnkDoWorkTwo opens a window with url = WorkTwo.aspx which also does some work
In my present solution when I click lnkDoWorkOne then a new window opens with WorkOne.aspx and works just fine. Then when I click lnkDoWorkTwo, then there's no new window at all but the contents of the previously opened window are simply replaced by WorkTwo.aspx. I need to have BOTH windows open with WorkOne.aspx and WorkTwo.aspx so that the user can view the contents in parallel.
Does anyone know how to achieve this?
Are you giving the same window name to the both window.open calls? If so, change the name of the window and you should get two separate windows.
window.open('WorkOne.aspx', 'window1');
...
window.open('WorkTwo.aspx', 'window2');

Refreshing a parent window when both are modal

This is a tough one that's left me high and dry, because its a unique variation on a more common problem.
I have a modal parent window spawning a modal child window (with a standard window.showModal call to open it). The user performs some actions on this new page, and then closes it. On the close, I want to refresh the parent modal window.
What makes this tough is that both are modal. I've seen solutions for how to refresh normally (window.opener.location.refresh(true)) and if the child is a modal window (window.dialogArguments.location.reload(true); where the parent window is passed as the 2nd argument).
Any suggestions on what to do? I think the modal nature of the parent is breaking the refresh, and I can't figure out how to work around it.
When you open a Model window with window.showModalDialog the code in the parent page is stoped, so the code after the opening of the modal window won't be executed until the child is closed.
Having said that, just try:
// Open the modal dialog
window.showModalDialog('your/child/url.com')
// after is closed, the parent will refresh it self
window.location.reload();

Categories

Resources