caller arguments for Flash object which runs JS - javascript

We have many flash banners which we don't control (we can't change their source code to pass parameters).
They run a single JS when clicked. This script is on our side, sits on the same domain as the banners.
We wonder how can we find from inside the JS any arguments regarding the calling Flash object, for example, the file name of the SWF, it's position on the page etc.
We tried using arguments.callee.caller in JS but with no luck.

If the SWF doesn't pass any of theses informations as arguments, you just can't figure out which SWF called your javascript function.
You can maybe get stack traces in JS, but they will be the same regardless of the callee SWF.

You might work around this by creating a common holder swf that loads in a banner and handle clicks from that swf, ignoring the javascript calls from the original banner. You could pass in a flashvar to distinguish between the different banners and pass any info to the js function.

Related

Javascript with COM object

I am writing an automation script using AHK and have already gone through their forums and live chat to no avail.
My issue is that I am using a COM object to navigate and click things on a webpage. But the navigation menu on the webpage does not change url's when going to another part of the website. Instead they use a "main controller" so the url in the address bar never changes but the webpage does.
I do not have access to the source code but from the element inspector in the web browser I know the name of the javascript function and the arguments it calls to go to the page I want.
I am wondering if there is a way, through the com object or other method, to call the javascript function even though I do not have direct access to the source code?
Thanks for any input.
Yes, of course there is. Just have your script access the address bar and past in the script. E.g.:
javascript:alert("Hello World");
And note, some browsers may strip out the first part and give you back a search result, so you may have to have AHK, after typing/pasting in the command, go back to the beginning and re-type the javascript: part.
Now, whether this works when you call a function up without referencing back to the source, I can't say, but then again, you could have given more details in your post.

How to use external ajax response in Chrome Plugin

I have a existing file ajax,js in my website that makes an ajax request and creates a global JSON object, searchResult using that response. Now I am creating a Chrome plugin, that requires this JSON Object inside it. I have a content script for the plugin viz. plugin.js and I want to include the object inside plugin.js file.
When I try to log window.searchResult from within plugin.js, it shows as undefined.
but when I use browser console, it shows the value as expected.
Please help me with this.
Problem
Chrome content scripts and the page's own scripts live in isolated worlds.
Content scripts execute in a special environment called an isolated world. They have access to the DOM of the page they are injected into, but not to any JavaScript variables or functions created by the page.
Your code works in the console, since you execute it by default in the page's context. To see what the extension sees, you need to switch it.
Solution 1a
First, the generic solution (works even if you don't control the webpage)
There is a way around this, by injecting some code directly into the page's "world" (or properly called, context).
After injecting the code, your page-level script needs to communicate with the content script to pass the data. It's possible with custom DOM events (as, as you remember, DOM is shared). The page-level script sends an event with the data in the event's details.
Alternatively, you can just attach the data to some DOM node, say, an invisible <div>.
Solution 1b
Since you said it's your page, you can skip the inject-into-the-page step and have a listener ready in the page's own code.
The content script sends a custom event to request the data, and the page answers passes the data back as described in 1a.
Solution 2
In theory, you don't even need a content script.
You can use the "externally_connectable" mechanism to speak with the page directly.
Note though that the page has to initiate the conversation.

Is it possible get current url with as3 without using javascript/ExternalInterface?

I have a project that i can't use the ExternalInterface to get current url from the browser...
So, someone know how i can get current URL from the browser without using ExternalInterface/JavaScript with the Flash/AS3?
Note: I can only use Javascript, HTML, CSS, AS3.
I asked this before on the Mochi forums: https://www.mochimedia.com/community/forum/topic/reliably-find-the-page-url
Long story short, there's no 100% reliable way unless you have some sort of control over where the SWF is placed - loaderInfo.url gives you the swf url, not the page one, and some of the time this can be the address of the preloader SWF (e.g if you make a game that goes onto game sites). You could try JavaScript, but that only works if it's enabled and sometimes you'll get the address of an iFrame, rather than the main page URL. Ditto for calling a PHP file.
Your best best is JS, but keep in mind that it's not perfect
var url:String = ExternalInterface.call("window.location.href.toString");
Note, you can do the same when you're embedding the SWF and pass the value in as a Flashvar
Maybe use flashvars to pass the url to your root on creation (look into swfobject.js)
Or look into: stage.loaderInfo.url

Avoid duplicate Javascript inside iframes

Here is a wireframe to ilustrate the structure of a legacy project that shows some performance issue:
For all dialogs (From jQuery UI) open a new iframe are created and all js from Home are re-downloaded and all objects are re-instanced. Can I create a reference from jQuery from Home to all new iframes and work in each iframe isolated scope?
For example:
[Home scope]
$("#some-el").data('foo', 'bar');
console.log($("#some-el").data('foo')); // results bar
[App1 scope]
//after defined in Home first run
console.log($("#some-el").data('foo')); // results undefined
PS: Remember this is a legacy architeture and all solutions must be consider this scenario.
I've encountered this situation before. One approach is to define some javascript that gets loaded into the iframes that just reroutes any function calls to top.functionCall() instead of containing their actual definition. It becomes very simple if all of your functions are under one namespace, like so:
Parent window js:
var namespace = (function () {
// all of your functions are in here as properties of namespace
})();
iframe window js:
var namespace = top.namespace;
One issue with this is any context sensitive functions (functions that rely or operate on the window object) will most likely break.
Actually, if all of these are hosted in the same place, the browser will NOT be downloading the files multiple times. Rather, it will be caching the first result, and then pulling from cache in the second. Iframes are treated as a separate context, so you won't need to worry about variable or form conflicts.
Assuming that downloading the same file twice is your primary concern, then you should be ok there.
An alternative design would be to use AJAX instead of iframed content - but having been where you are in working with legacy apps, I realize how hard that can be to do without real JSON / REST calls available. One thing I've done is changed the views inside the iframes to be "partials," returning only the necessary HTML contents without the HTML head etc., and loading them using $.load(). This gets complex as you will need to execute bindings post-load and carefully track form ID's etc., but it can be done.

Actionscript and Javascript conversation

I am new to actionscript 3.0 and am using Adobe flash CS6. I need to pass the value of a javascript variable to my actionscript code embedded in my timeline (I am not programming in a seperate .as file but the timeline itself.). I need to compute a value using javascript, and then I need to use that value in my actionscript code. How can i do this?
My purpose is to return a String value using a javascript function and then display the same String in a text area in my flash movie. (test1.swf)
But i see nothing in the textarea....
I have attached the code as well as other details in a text file..
plz follow the link
http://share-ideas.in/saurabh/App/test/code.txt
ExternalInterface maybe a bit tricky for beginners. There are quite a few conditions that need to be met for the communication to work:
Either you test on a server, or add the location of the swf/html files as allowed in the Flash Player Security Settings
The AllowScriptAccess is set to "always"
The <object/> tag's name attribute should match the <embed/> tag's id. This should ensure js communcation across different browsers.
Depending on how confortable you are with coding, you can either try the ExternalInterface example and simplify/modify it for your needs or use SWFObject which should make it easier (and cleaner) to work with flash and js

Categories