I know that this question was asked earlier but the OP didn't get any suitable answer.
So the question is:
How to access page context to call some js function in FF overlay (toolbar in my case).
I have <toolbarbutton> element with onclick="nextTrack()". nextTrack declared in the included JS file. Function executes when I press toolbar button, but I cannot exec function that I'm sure exists on the page.
I cannot modify the page, because it is an external site, but I really want to make my extension.
Of course I can (and I am) use something like mainDocument.getElementById("player_play").click(), but page already has an audioPlayer object that has all ability I need: play, pause, next, prev etc.
For more cleanliness I make an extension to control an audio player for vkontakte social network (well known social network in exUSSR countries). So you can look at example page here, maybe it can be helpfull: http://vk.com/wall6843477_2327.
When you start listening the bar with controls must appear you can find lot of stuff like audioPlayer.nextTrack(); audioPlayer.prevTrack(); etc.
You aren't accessing content directly, you are rather going through XPCNativeWrapper. This means that all JavaScript properties defined by the content page are invisible (which is a security feature). In your case, the simplest secure solution is to use the javascript: protocol:
mainDocument.defaultView.location.href = "javascript:void audioPlayer.play()";
This way you won't be able to get a result back but from it seems that you don't need to.
Related
I am working on a school project and the goal is a rather difficult click jacking. I am using a virtual machine and a host-based domain. Essentially, I have a very vulnerable shopping website and I am trying to overlay iframes on top of some buttons on the site.
My first approach I created an iframe when the user clicked my "eViL" Button to host the vulnerable website in. From here I have tried inserting more iframes based off of the page after it loads (since the buttons are dynamic). I have tried doing this by doing something like this:
iframe.onload = function(){
var innerDoc = iframe.contentWindow.document;
};
However, I soon realized that this just causes an error because of the Same Origin Policy of the Browser.
My second approach that I can think of is possibly sending some script tags through a GET request. However, I am not quite sure how to go about doing it as I am not super familiar with Javascript or HTML. I'm sure it will have to be a little hacky to do it by escaping characters and what not but, is it really possible to do it this way?
My second kind of overall question is was my logic from my first attempt flawed? Or was there another way to go about doing this whole process? Which approach seems to be the correct one here?
I am looking to implement special functionality for my website, where loading a page that has multiple other consecutive pages (such as a search result) pre-loads the next page into the browser, accessible via the "forward" button. This sort of functionality is seen on the MSN News website; see the following screenshot.
I am looking to have this functionality implemented through JavaScript on a static deployment, as in, the server would just send everything client side. Is this at all possible? Where could I look for documentation for such a thing? I have already attempted to search for the answer to this inquiry elsewhere with no avail. Thanks in advance.
I'd avoid looking to use the forward button as its not a primary target but rather preload links on the page like the next button, but rather do it through something called InstaClick. If you're looking to specifically target the forward button itself best place to look is at the History API but thats browser specific. I've attached Mozillas doc on this.
https://developer.mozilla.org/en-US/docs/Web/API/History_API
http://instantclick.io/
https://github.com/dieulot/instantclick
I would like to get a value of an input that is on an Iframe.
I would like to get this value when I click on a button that is on the mainPage.
well, I have this piece of code
Javascript on the MainPage:
var targetDiv = document.getElementById('CP_dem');
Html on MainPage:
A tab that when you click on it, it load the Iframe
and a button that call the javascript function
Html on the Iframe:
Zip Code : <input class="textForm" id="CP_dem" type="text" name="CP_dem" maxlength="5" size="5" value="42101">
I would like to get the input value when I click on my MainPageButton.
The javascript code show that "targetDiv" is null.
Can you please help me.
thx
The first thing you have to tell is is:
Is the iframe hosted on the same http host as the parent website? If not, you will run into javascripts same origin protection, read about it at: http://en.wikipedia.org/wiki/Same_origin_policy
In short: You will not be accessible to access the content. But wait! There is a workaround which I will explain after dealing with the second case, where the http host is the same!
So lets talk about that second case. Well then the job is easy...
You just have to access the iframe (probably give the iframe tag an id "example"). Then you can access the window using example.contentWindow.document or example.contentDocument
Whichever is set, depends on the browser. You will have to do some checking in js. Something like
if(document.getElementById('contentWindow.document').contentWindow) {
ifdoc = document.getElementById('contentWindow.document').contentWindow.document
} else {
ifdoc = document.getElementById('contentWindow.document').contentDocument
}
Then you can access the form and element just as you do in javascript, i will not cover that here...
So lets jump to the interesting part of this answer! Lets work around the same origin poliy. This is also called "cross site scripting" (go ahead and google that...)
So basically it comes down to one thing:
There is one property that is accessible from the child as well as from the parent document!
It is the document.location property!
So what can you do?
The child site can modify it and then the parent site can monitor it and react to changes.
Another nice feature is the url fragment (the part which comes after the #). This part does not reload the website, so javascript can modify it happliy and the parent site can poll it in regular intervals and react to it...
Basically this provides a ground for communication for parent and child document which can be worked on. There are beautifully designed librarys for that! The javscript version of "log in with facebook" was based on the same principle!
What this means is that the child document has to cooperate with the parent, therefore it is intentional and both parties basically work together on the job.
So this is OK and it is ok that they work around the same origin policies.
Hope this covers your question in theory and gives you something to work with in praxis!
Have a nice day on SO :)
I've been trying to figure out how to let a Greasemonkey user script open up a search engine page in the background and fetch search results. I've tried to look up examples to open up HTML pages, but afaik all examples of requests handle ajax calls instead of html calls.
Any hints would be grateful.
The standard Greasmonkey GM_xmlhttpRequest function (link to API) can handle any type of request, not just JSON. Under examples, check out the GET request code snippet.
Watch out though. Search engines like Google will not appreciate the screen scrapping (and will probably block you if you grab too many results too quickly).
Haven't done this in GreaseMonkey (don't know really in fact if you can do it);
though if you really want to do it by opening a new tab, and if you're not using any GM-specific stuff in your code (and don't want to run the code automatically, well, this can be an obstacle), you can take a look at Custom Buttons extension.
With it, you can create buttons that have access to Firefox internals and invoke stuff like gBrowser.addTab().
But working with CB is a bit more tricky than in GM.
These posts may help if you're interested:
JavaScript alert not working in Firefox 6
Mozilla: Tabbed browser / Manipulating content of a new tab
Code sample copied from Mozilla:
var newTabBrowser = gBrowser.getBrowserForTab(gBrowser.addTab("http://www.google.com/"));
newTabBrowser.addEventListener("load", function () {
newTabBrowser.contentDocument.body.innerHTML = "<div>hello world</div>";
}, true);
I've done something similar.
All you have to do is save the GM_xmlhttpRequest response in a DIV.
With this DIV you can do whatever you want (show, hide, display only some of the content, etc)
Just take a look at my script source code.
I'm positive it will help you.
I know you don't need, Mr. 14k rep, but i'll break it down for you anyway :)
function conectar() calls GM_xmlhttpRequest [GET] and stores only the part of the content that i want to use in #divtempora, which is a dummy div that the user never sees (hidden).
Then function resp_dxlegacy() walks through the dummy div, save the info i want in a variable and calls conectar() again passing this parameter and storing the content in another div, which is, finally, displayed to the user.
Quite simply, I have a SWF embedded in an HTML web page and want to move to a specific frame when a trigger is clicked.
But nothing happens when I click the trigger, as though the js just doesnt communicate at all with the swf.
SWF is written in flash cs4 (a3)
The link to the website is http://simplywebdzine.com/test.html.
I have read the text books over and over and researched high and wide on the internet and as far as I see I have done everything correctly but I cannot get this to work.
The swf is very basic, just a green box moving accross a small stage.
The desired gotoframe would make it cross at a lower height (just a dry run for a more complicated swf)
Would really appreciate someones help if you could possibly find out from the source code what is going wrong.
Many thanks
Steve
It looks to me like you have two problems.
You do not have the correct id for your <object> according to your javascript. The object id is "mymovi.swf" while your javascript is targeting "mymovi" as the id.
Even if I change your id using firebug, the function still does not fire off in the flash and I get an error about the function not existing.
Have you added a callback method in flash? something like flash.external.ExternalInterface.addCallback("GotoFrame", gotoFrameHandler) ??