I can open a new window using window.open() in ExternalInterface.call() but then I want to be able to write contents to the new window. Since, I cannot get the reference of the window back from window.open() call, I am not able to do anything to the window once it is opened.
Please note: I do not have any control over the HTML in which my swf is displayed.
Has anyone been in this situation before?
Update: After a few hours of trial and error I found you can get out of this situation by storing your window reference globally and referring to the same global reference whenever you need to access the new window.
are you trying to simply present a new webpage from your .swf? if so, external interface is not required. you can simply use navigateToURL:
navigateToURL(new URLRequest("http://www.stackoverflow.com"), "_blank");
however, if you want to make a popup window with a custom size and visibility of the browser toolbar and scrollbars, you can call external interface like this:
if (ExternalInterface.available)
{
ExternalInterface.call(
"window.open",
"http://www.stackoverflow.com",
"win",
"height=200, width=300, toolbar=no, scrollbars=yes"
);
}
It is possible if you store the name of the javascript window reference variable. But, you might want to consider the fact that if you don't have any control over the HTML where the swf is displayed, you can't be sure that the javascript access won't throw a SecurityError based on various security policies laid out by the flash team.
Related
I am using window.open to open a new window which will send some message to the parent window using window.opener.postMessage.
This child window URL is arbitrary. I mean there is a textbox where the users can give the URL and it will be opened using window.open.
Although the user is suspected to use the URLs that are supported, it is also possible that some random URL will be used. In this case, I don't want to child window to make any changes to the parent window, especially to the parent location.
How can I avoid this issue? I've tried to use noreferrer,noopener; however, that breaks entire cross-window communication altogether, which is not desired.
I have two bookmarklets that work individually
1)
javascript:(function(){window.open("http://mail.yahoo.com");})();
2)
javascript:(function(){;document.getElementsByClassName('btn-compose')[0].click()})();
(the above lines of code were put through a bookmarklet generator here:
http://ted.mielczarek.org/code/mozilla/bookmarklet.html
and each bookmarklet works fine)
but when they are together like so:
javascript:(function(){window.open("http://mail.yahoo.com");document.getElementsByClassName('btn-compose')[0].click()})();
or like so:
javascript:(function(){window.open("http://mail.yahoo.com");})();
javascript:(function(){;document.getElementsByClassName('btn-compose')[0].click()})();
the compose window does not open. I have a feeling the DOM is not ready.
but this fails:
javascript:(function(){window.open("http://mail.yahoo.com");})();
document.onreadystatechange = function () {
if (document.readyState == "complete") {
javascript:(function(){;document.getElementsByClassName('btn-compose')[0].click()})();
}
}
You have several issues going on.
window.open() opens a new window. If you wanted to operate on that window, you would have to get that window handle and then get the document from THAT window. Right now, you're trying to operate on the original window with your second script.
A script launched from one window cannot access a different domain in a different window due to browser security restrictions.
It appears to me that you will either have to manually launch the second script after the Yahoo window opens. Or, you will need to use a browser plugin that can access the new window.
It also appears that you're trying to solve a problem that is probably already solved (bringing up a compose window in Yahoo mail). There is probably a URL you can just open in a new window that will start the compose window directly without having to hack into the window to push a button.
See this post for info on a URL that will take you to a Yahoo compose window. The general form of the URL is this: http://compose.mail.yahoo.com/?to=TO&subject=SUBJECT&body=BODY
I have a parent opening a new window, and trying to detect when the child window has loaded. In Chrome, I've tried
open('http://www.google.com').onload = function() { alert(location.href); };
but that doesn't seem to work.
Why doesn't the above method work? Are there alternatives?
If you want to be absolutely certain that a page has loaded, you can use messaging.
If you are able to use HTML5, there is a new feature called web-messaging.
This works very well on cross domain sources.
If HTML5 is not an option, use JS instead. I used a simple jQuery plugin called: windowmsg. It has worked excellently for me. I'm really not sure about this working on a cross site environment, but I think it should.
Beware of the security issues that these kind of solutions offer.
The method as it is should work(and works for me), but not when opening a window with a document from a different domain.
For security-reasons the new window will not dispatch the load-event to a document from another domain.
Technically speaking the child window and parent window are two different instances of the browser. We call them as child window and parent window. They do not have access to each other.So its not possible to perform any action in one window on the click of HTML elements in second window.
So, I suggest that you should not open a new window if you need access. You can use fancybox or lightbox that is effectively a part of the same window and that, you have control.
I am trying to select a newly-opened window using Selenium, and the select_window() method requires its WindowID.
I have tried using the window's title, as other places have suggested, and turned on Selenium's debug mode, as the documentation suggests to see a window.open intercept, but neither option seems to have worked.
Is there just some simple javascript command I can enter in the new window's console to view the window ID?
So there are two things, as I am not sure what is your exact scenario.
So considering you have opened the new window, while doing so, you can define the window id.
So for example:-
$sel->open_window("http://www.google.com", "Chris Cooper");
$sel->select_window("Chris Cooper");
Or if the new window is popup(not explicitly opened by you), you could simply use
$sel->select_pop_up();
I ended up extracting the link URL from the anchor, and simply navigated to that URL instead of opening a new window.
For Safe Use
Perform
1.$sel->get_all_window_titles();
2.$sel->get_all_window_ids();
3.$sel->get_all_window_names();
From this Either we can use [select_window id/title/name] Simple.
I know there have been several similar questions, but I haven't seen an answer to my specific need: Is there a way to click a button in a separately launched web page? For example, I launch another web page via:
<a href="x" target="y"> or
window.open()
Can I then click an input button in that launched web page programmatically?
Unless the page is underneath your own control or resides on the same domain then no, it is not possible. This would be cross-site scripting and all browsers have security sandboxes in place to keep something like this from happening. Why are you trying to programmatically press a button on a page that you're also programmatically opening?
Yes. When you do window.open it will return you a window object. Var win = window.open(); win.fnSubmit(); assuming fnSubmit is the function on the other page that will do the.clicking. and both pqges on the same domain.
This is a technique used by some hacking injection attacks. Basically you can inject javascript into the querystring that can attach itself to the DOM, change an image or swf file source or simply run when the page is loaded; example here and example here.
Or if you already know the structure of the other page you can directly target methods or objects.
But as these are not nice things I assume that you have good reasons why you can't touch the code on the receiving page but want to adjust its behaviour?
You can click on any element you can select.
You can only select elements in windows that you have security privelages to.
You have rights to your own window, and rights to windows within the same domain & security.
To access the element you'll need the window object, which is returned from window.open
var newWin = window.open(siteYouHaveAccessTo);
newWin.document.getElementById('foo').click();
If you're trying to click on the Search button on www.google.com, you're SOL.
Survey says... maybe. If you've done your homework, you will probably be able to get communication to happen within the same subdomain. It gets progressively more difficult from there -- I've never had consistent cross-browser sub-domain support for manipulating JavaScript between two windows (or iframes).
That said, if they are the same domain, it is a matter of descending into it. If I have:
Window A opens Window B
Window B declares var winBVar
Window A is able to access winBVar after, and only after, that variable is declared (as in, you still need to wait for document.onload, etc)