views:

84

answers:

1

Hi all,

Question says it all, dividing it into two parts:

1- Grabbing url when chrome extension is clicked, of current tab(on focus) - CHROME SPECIFIC.

2- Setting the same in a Textbox value, in one of frames of web page.Which means, the textbox resides in a.html where on webpage it's <frame src="a.html"> -CHROME/JAVASCRIPT/HTML specific.

Please help, with either/both parts. Thanks so much.Appreciate it.

A: 
  1. Get the current url with location.href if the full URL is needed or location.pathname for just the path.
  2. Here's one way to access the frame and update the text box with the current location. Domain, protocol and port must match for you to be able to access the other iframe.

code:

var doc = window.frames['frameName'].document;
doc.getElementById('textBox').value = location.href;
Anurag
Thank you Anurag,Though location.href returns something like chrome-extension://somekeyslikechars/background.html and not current tab/or tab in focus' URL .. any clue? p.s. I did not tried 2nd step yet, since still stuck with first :-/
chrome.tabs.getSelected(null, function(tab){ alert(tab.url) })It returned the current tab URL. Thanks! (works fine!).
No success with second part though, guess Content Script will be required, not sure, how to use that? :(Please help.
Glad you got through the first hurdle. Unfortunately it seems that `window.frames`, or `frame.document` is inaccessible to your extension's sandbox. Try with `contentWindow.documentElement` which seems to work according to this [article](http://blog.afterthedeadline.com/2010/05/14/how-to-jump-through-hoops-and-make-a-chrome-extension/).
Anurag