I am trying to change the url of a currently open tab in javascript firefox extension
Any pointers please?
I believe it's "gbrowser.loadURI()". Try reading this page on MDC about interacting with the global variable gBrowser, and here about the loadURI method.
The mozilla doc mentioned by TML has sample code for this under "Reusing by other criteria", but it's broken. The corresponding talk page says to add this line to fix it:
tabbrowser.loadURI(url, tabbrowser.currentURI, "UTF-8");
However, if you've already got the tab object (say from calling addTab earlier) then I think it's simpler to do:
gBrowser.selectedTab = mytab;
gBrowser.loadURI(myurl);
I don't see any way to change the URL of a tab which is NOT selected, but that would be nice - I hate stealing focus.
UPDATE: here's how you do it w/o selecting the tab. Simple:
gBrowser.getBrowserForTab(mytab).loadURI(myurl);
Related
Is it possible to use Chrome's JavaScript Console to close all tabs for a specific website or a URL/title regex - e.g. closing dozens of Stackoverflow tabs that are using up memory instead of close them one by one?
This is not possible to do with the JavaScript console. The JavaScript console has no way of interacting with the browser in this fashion.
Just tried this and it seems to work in Chrome. Although it does mean that you have to programmatically open the window as well:
mywindow = window.open('', 'windowName', '', true);
then you close it with:
mywindow.close();
See this answer. Basically you need a reference to do what you're doing. You can't find by title or URL.
I have this and i can't get it to work on Safari for OS X (Safari 8.0). It works on Firefox and Chrome but i simply cannot get it to work in Safari.
function myChangeHandler()
{
window.open(this.options[this.selectedIndex].getAttribute('value'), '_blank');
this.form.submit();
}
What am i missing?
Thanks
I'm not sure what doesn't work since there is no specific problem that is posted but I'm guessing it's the window.open()?
I found this article
window.open(url, '_blank'); not working on iMac/Safari
it might be the one you were looking for.
From:
Kelly J Andrews
The standard window.open() JavaScript method cannot be used to open a new tab and window from a global HTML file or an extension bar. Instead, the global file and extension bars have access to the SafariApplication, SafariBrowserWindow, and SafariBrowserTab classes, whose methods and properties allow you to work with windows and tabs.
It goes on to explain how you can use
var newTab = safari.self.browserWindow.openTab();
I am trying to edit javascript on a site using Chrome's Developer Tools. I have read about 30 accounts of how to do this as well as watched a few videos. The fact is, when I go to the sources tab and open the file I want to edit, I can't do anything to it. Is there some step I am missing?
I can create break points, step through, etc... I just can't edit. Was this functionality removed recently?
I know this question is stale, but I just had a similar problem and found the solution.
If you have the file prettified, Chrome will not allow edits. I turned it off and was able to edit. Willing to bet this is/was your problem.
You can edit javascript in the developer tools on the "Sources" tab, BUT it will only allow you to edit javascript in its own file. Script embedded in an HTML (or PHP) file will remain read-only.
It has some limitations:
has to be a JS file. can't be embeded tags in a html page.
it cannot be prettified.
I don't know if you need this to save permanently, but if you need to just temporarily modify the js:
I can copy that javascript I want to modify into a text editor, edit it, then paste it in the console and it will redefine any functions or whatever that I need to be redefined.
for instance, if the page has:
<script>
var foo = function() { console.log("Hi"); }
</script>
I can take the content between the script, edit it, then enter it into the debugger like:
foo = function() { console.log("DO SOMETHING DIFFERENT"); }
and it will work for me.
Or if you have like,
function foo() {
doAThing();
}
You can just enter
function foo() {
doSomethingElse();
}
and foo will be redefined.
Probably not the best workaround, but it works. Will last until you reload the page.
I did search "chrome dev tool edit javascript". This page is the first search result. But it is too outdated, it does not help me.
I am using Chrome 73, this version of Chrome has "Enable Local Overrides" option. Using the function, I could edit a javascript and could run and debug.
My solution:
In the devtools preferences check the Enable local overrides.
Go to network tab, find the file you want to edit, rigth click on it and select Save for overrides (on the sources/overrides tab you need to add a local folder)
The file appears in a new tab on the Sources tab as local copy, so you can edit this file, and after site reload the new (and edited) override file will load on the site!
Is there any tool or addon which can be used for testing or identifying Javascript functions in real time (i.e. on click or some events )..
e.g. on a website, I want to know after clicking on a link, which all JS functions are being called/executed..I know sometimes it is stragightforward from the code, but in case it uses JS libraries like jQuery, the actual function call is made from otside..
How can I do that?
*I'll really appreciate if, alongwith the addon, you just write a short description as to where can I find the Javascript finction tracking in that **
Thank you.
Try Firebug. It's one of the most useful firefox addons. Grab it here:
http://getfirebug.com/
Dragonfly (Opera), or Firebug extension for Firefox, or any other good javascript debugger
See Visual Event. It is a bookmarklet that overlays element event handler information.
FireQuery is available as a firefox plugin which adds handler information inside of firebug.
Firebug includes a JavaScript profiler. Give it a try.
http://getfirebug.com/javascript
In Chrome, right click the page and choose Inspect element, go to the console, start javascripting! Choose the scripts tag to get debugger functionality.
I use :
Window.showModalDialog(...)
to open a dialog window,
I want show some HTML code in this window, but I don't have a file. (Can't use URL to visit)
like show "hello world!" in this dialog window.
Can I do it?
Interesting question!
I'm not an expert in modal dialogs, but I don't think you can, because it's in the nature of a modal dialog to block any further code from being executed until the window is closed again.
I thought about using a data: URI that you could use as the first argument to showModalDialog instead of a normal URL:
window.showModalDialog("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D" ....);
but according to the MSDN page on data: URIs, that will not be supported in Internet Explorer. (see the "Remarks" section on the linked page)
It might work in Firefox, though: More on data URIs at Mozilla Developer Central
Update: It works in Firefox: JSFiddle but, as expected, not in IE. You only get a blank window there.
Good question and answer. (+1)
I just thought I'd add, that if you do need to enter HTML into a modal dialog, you may want to look into using a Javascript library to accomplish it. I've used Dojo's "dijit.Dialog" several times with HTML, including images, form controls etc... You can style it however you like, and it works well cross-browser.
You can check out a few example of dijit.Dialog's use over at DojoCampus.
Cheers.