admin管理员组文章数量:1420575
After clicking on the button i need to open some link in new tab, and than after the page would be loaded, I need to programmatically perform some actions on this page (like clicking on proper GUI elements etc).
For example this code should open in new tab and after that click on "Tags":
<button type=\"button\"
onclick="window.open('', '_blank');
document.getElementById('nav-tags').click();">Click Me!
</button>
but the function document.getElementById('nav-tags').click()
does not call.
After clicking on the button i need to open some link in new tab, and than after the page would be loaded, I need to programmatically perform some actions on this page (like clicking on proper GUI elements etc).
For example this code should open in new tab http://stackoverflow. and after that click on "Tags":
<button type=\"button\"
onclick="window.open('http://stackoverflow.', '_blank');
document.getElementById('nav-tags').click();">Click Me!
</button>
but the function document.getElementById('nav-tags').click()
does not call.
- there is no way of doing this (for security reasons) but what you could do is load stackoverflow./tags – avidenic Commented Jan 8, 2015 at 8:02
- It's just example with stackoverflow. . These needs for SPA (single page application) website – walter Commented Jan 8, 2015 at 8:09
- If SPA is made with angular, you can still open direct url. Other ways of doing this are: using cookies to store/load information between tabs or local storage. But they must be in same domain/have same parent. – avidenic Commented Jan 8, 2015 at 8:15
- Possible duplicate of Call a JavaScript function across browser tabs – Ivar Commented Sep 18, 2017 at 19:45
3 Answers
Reset to default 2As I said in ment, there is no way to directly municate between tabs/windows.
There are way around this however:
- when opening another tab, send data you need in url (like i suggested in ments stackoveflow./tags)
- municate using cookies (https://stackoverflow./a/4079423/3600886)
- municate using local storage (http://dev.w3/html5/webstorage/) - there is a library for that: https://github./diy/inter.js/
If your usage is to just show some data upon page load, I'd say go with first option, it will work across all browsers, free of any other restrictions.
With other options you will need pages to be on same domain or have same parent window, plus local storage is not supported by older browsers.
Create the tab from JavaScript and you can access the tab with JavaScript and place a onload function
var w = window.open();
w.onload = function(){
};
You can also put the onload function in the tab:
window.onload = function(){
}
You need to write your JS in .ready event. So it will be called when whole page DOM is ready:
$(document).ready(function () {
document.getElementById('nav-tags').click();
});
本文标签: javascriptCall function after page was loaded in new tabStack Overflow
版权声明:本文标题:javascript - Call function after page was loaded in new tab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745336492a2654062.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论