firefox - How to let a sidebar execute javascript code from the main document? -


i'm working on firefox sidebar loads webpage in main document. i'd call javascript function main document in response of pushed button on sidebar. how can sidebar cause main document execute 1 of javascript functions? far, i'm having variable containing javascript code, how can executed? (in context of loaded website?)

dr.molle correct answer love working examples.

console.log("opening new page @ http://example.com"); page = window.open('http://example.com'); console.log(page); console.log("calling alert on opened page"); page.alert("i opened , previous windows js called me!!!!"); console.log("called alert"); 

example page => [removed. see update below]

results:

alert initiated other page console logs

note: had allow popups demo code work issue question. ; )

firefox popup blocked notice

update:

so doing

page.alert() 

worked because didn't have wait page finish loading work. in order able call function script on loaded page have ensure script has finished loading. illustrate changed example.

example page => http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-call-function-in-opened-page.html

the js looks this

page = window.open('http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-the-other-page.html');  var initotherpage = function() {   try {     page.showmethemoney();     console.log("it worked!");   } catch (e) {     console.log("failed call function on other page because: "+e);     settimeout(function() {       console.log("trying again")       initotherpage();     }, 1000);   } } initotherpage(); 

console output

alt text

opened page

alt text


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -