Running Javascript on top of window.open() window -
say opening webpage (www.facebook.com) passing url window.open() function. window opens new browser since have used "_blank" in window.open() function.
i want run own javascript on newly opened window. when researched, found solution have added in source code posted below. unfortunately javascript not working on newly opened window. me in ?
<!doctype html> <html> <head> <script> function myfunction() { var url = document.getelementbyid("mytext").value var newwindow = window.open(url,'_blank','height=400,width=600,left=10,top=10,scrollbars=yes,menubar=yes,titlebar=yes') var newscript = newwindow.document.createelement('script'); //console.log(newscript); newscript.setattribute('type','text/javascript'); newscript.setattribute('src','c:/users/30216/desktop/jquery_edited_new1.js'); newwindow.document.getelementsbytagname("head")[0].appendchild(newscript); //console.log(newwindow); //newwindow.document.head.appendchild(newscript); } </script> </head> <body> <table align = "center"> <frame> <tr> <td class="url">enter url:</td> <td> <input type="text" id="mytext"></input> </td> </tr> <tr> <td> <button id="browser_open" onclick = "myfunction()">submit</button> </td> </tr> </frame> </body> </html>
you can access document according same-origin-policy.
if open web page facebook , webpage opened facebook.com not use same domain, protocol , port not able access document of page.
imagine you if without policy. e.g. able open facebook, secretly install key logger , tell user log in.
Comments
Post a Comment