I want to write a Firefox addon that could get the content of the address bar in real time, for example this addon will change every "a" to "A" just as the user pressed "a".
The problem is that I couldn't find any way to do that in Javascript, is there a way to do it (getting the address bar content in real time)?
You didn't actually say at what point you're stuck.
First you need to create a simple extension that overlays the main browser window (browser.xul). Building an Extension - MDC, URL Fixer - good example extension
Then you'll need to attach an event listener to the URL bar (key words: addEventListener, events). You'll probably want to listen for "keypress", although you should read the documentation on various events available. You can search through Firefox or other extensions' source to see what element they attach the listener to. You can inspect the DOM tree (to see the elements available) in the DOM inspector extension.
In the event listener you should check and update the URL in the Location Bar (gURLBar.value, IIRC). You'll also have to do something to preserve the caret position.
Don't hesitate to ask for help in the forums listed at https://developer.mozilla.org/en/Extensions
A Firefox extension can absolutely control the address bar. Try looking at the source code for the omnibar extension. (To get at the source code, install the extension and then poke around your Firefox profile folder)
You may need a listener to track urlbar changes such as:
gBrowser.addProgressListener(myExt_urlBarListener,
Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
The urlbar can be updated by this command:
document.getElementById(comVar.URLBAR_ID.gui).value
You will need to detect each keystroke with Javascript by reading the url with the above code. If you need more details then extract and check out the code in one of the spoof addons for firefox.
If you are simply trying to modify the text of the address bar without redirecting the user, this is not possible.
Whenever a property of the location object is modified, a document will be loaded using the URL as if window.location.assign() had been called with the modified URL.
If the browser allowed you to use javascript to change the string in the address bar without redirecting the user, it would be prone to phishing. That's not what you're trying to do is it?
In JavaScript, window.location.href will give you the value, and you could watch for it onkeyup, but AFAIK, you can't write back to the location field without loading the page at whatever value you set it to. What I mean is, if you did the following, it would reload the page:
window.location.href = window.location.href.toLowerCase();
I'm not familiar with how Firefox extensions work, but maybe there is a more "native" way to do this?
Related
I'm scrutinizing the phenomenon of blicking the context menu via JavaScript.
This is how such a menu can be blocked:
document.addEventListener('contextmenu', event => event.preventDefault());
And I've read in an article that such blocking can be reset if in the address bar we input:
javascript:void(document.oncontextmenu=null);
I tried in Chrome under Windows. This excertpt can't be input as a whole. It looks like this in the address bar
void(document.oncontextmenu=null);
And then it starts searching for this string in Google. Well it it not what we are looking for.
But if we create a bookmark with that desired code, and use it on the target page, it works perfectly. In other words, it unblocks the context menu.
Threrfore two questions:
1. What is the difference between manual insertion of the script above into the address bar and the use of the bookmark?
2. Can this script be used not in the bookmark to achieve the desired result? Does it depend on the browser or what does it depend on?
For fun, paste this into the chrome address bar and it will search for 'void(alert('foo'))'
javascript:void(alert('foo'))
Then, type it in manually, hit enter, and you'll get the alert.
Not sure what this answers, but I thought it's worth sharing.
I want to ask that how could i restrict the user not to copy the URL displayed in firefox. One option is to Disable the URL not to be shown to the user
other one is to Disable the address bar so that the URL can be seen but cant be copied.
But i dont know how to achieve any of these using javascript.
Any help along with code snippet would be highly appreciated.
Thanks in advance
You have absolutely no control over that portion of browser UI.
This cannot be done. Not via javascript, and probably not through any other legitimate means, either.
You can open a new window without the address bar using the window.open method.
But
certain browsers (think mobile...) don't support hiding the address bar
users can possibly disable this feature in their browser settings
there is always more than one way to copy the URL, not only from the address bar
I am displaying an online internal website.
Upon clicking on a button "A" it processes a task, and goes to another HTML page. However, this direct address is like "hidden" (hard to explain).
For example, for each page I am accessing by simple button click, it's always the same URL (like http://host.com for every page I display from them).
I am using Firefox, and I need to know how to get the exact HTML address (or direct URL) used for displaying these full new pages. I managed to do it few months ago, but not anymore.
It will help me to automate some tasks and bashing programs. I am openned to any linux browser in case you find a way to help me. Thanks a lot.
it sounds like domain masking is used. you could check the source and see if a frame is being used on the page. the source should indicate the src of the frame, revealing the location of the page.
<frame src="page.html">
If the button uses window.open to navigate to the url, you could override that method and intercept the url there:
var oldOpen = window.open;
window.open = function(){
console.log(arguments[0]);
oldOpen.apply(window, arguments);
};
I would like to hide the status bar in Firefox when the mouse is over a link. Here is what the status bar is :
http://support.mozilla.com/en-US/kb/what-happened-status-bar
I already tried window.status with javascript but it doesn't work even if I set dom.disable_window_status_change to false. I didn't find any add-ons ever.
Does someone have a solution ?
NB : this is only for a web application which won't be published on the Internet, my goal is not to hide a target link :)
Thank you.
This won't be possible / allowed by the browser for security reasons.
If this is an absolute requirement, is specific to Firefox, and you control the web browsers for the users that will be using this application, you could write your own Firefox extension to do this for your specific site.
This will not work because this is built in for safety reasons.
To prevent phishing for example or other bad things you can do.
I mean I'm not sure but what you could do is leave the a href ="" tag attribute empty or just insert href="#" and add some javascript which redirects the user to the page you want when he clicks that link. But I'm really not sure if this would work in the way you want it !
You can't hide it when it is over a link, but one way to get around it would be to attach click events to span elements that change the window location. So they would act like links, but there wouldn't be a href attribute to show in the status.
I am trying to initiate a click event for multiple instances of an element with a javascript bookmarklet. My goal is to be able to click on the bookmarklet and have it delete specific elements, such as whenever a button says remove. Could you help me with this please, I have tried vark.com and other sources to find this answer.
My goal is to achieve this in Google Chrome, can you help me?
Updated: Here is a more detailed explanation
<a class="page_link" title="Visit Page" href="http://www.jitbit.com/macro-recorder/versionhistory/" target="_blank">Version History - Macro Recorder, Macro Program, Mouse...</a>
This can be found by having PageMonitor installed in Chrome, clicking options and inspect element where it shows the name of the site you are monitoring.
Example:
Version History - Macro Recorder, Macro Program, Mouse...<--- This is the link
advanced rename remove Last Check: 11 seconds ago.<--- These are the options
Perhaps nodes was the wrong term, let me see.
remove
Where it says remove, I would like to initiate a click event that will press the Remove button every time it occurs Screenshot of PageMonitor options window
Thanks for explaining what you want to do. Unfortunately, I don't think this is going to be possible. Playing with PageMonitor, it doesn't appear to be possible to execute javascript in the address bar (necessary to make a bookmarklet) and have it affect the extension page.
The code to implement the feature you want is very easy though, and they could probably just add it to the extension if you asked them to. Here's the code:
$('.stop_monitoring:not(:first)').click()
Sadly, as I said, I don't think you can bookmarkletify this due to zone restrictions. Unsafe browser JS is run in a different zone from trusted extension JS. Hope this helps. :/