admin管理员组文章数量:1392007
So basically I have jquery code on a page where:
- Open a new popup window
- Display rails view page
- Manipulate items on a newly opened page
Don't know what sort of solutions are there, however I thought it should be really easy.
That's the code:
// open a popup window for example /fault_books/3
popup = window.open("/fault_books/" + <%= @fault_book.id %> , "popup");
// trying to get the scope of the element
var module = $(".module-logo", popup.document.body)
// manipulating the element
$(module).hide();
So basically I have jquery code on a page where:
- Open a new popup window
- Display rails view page
- Manipulate items on a newly opened page
Don't know what sort of solutions are there, however I thought it should be really easy.
That's the code:
// open a popup window for example /fault_books/3
popup = window.open("/fault_books/" + <%= @fault_book.id %> , "popup");
// trying to get the scope of the element
var module = $(".module-logo", popup.document.body)
// manipulating the element
$(module).hide();
Share
Improve this question
edited Jun 11, 2013 at 12:28
palaѕн
74k17 gold badges122 silver badges139 bronze badges
asked Jun 11, 2013 at 12:16
Jackie ChanJackie Chan
2,6626 gold badges36 silver badges71 bronze badges
6
- Or may be there is a way to add javascript to a created popup? – Jackie Chan Commented Jun 11, 2013 at 12:17
-
Did you try:
module = popup.$("body")
? – Stijn Geukens Commented Jun 11, 2013 at 12:23 -
Or try :
module = $(".module-logo", popup.document.documentElement.outerHTML);
– Mohammad Areeb Siddiqui Commented Jun 11, 2013 at 12:24 - What does happen when that code executes? Note: "nothing" is not a suitable answer; it's at best inplete and at worst an outright lie. Have you checked your browser's console/developer tools for errors? – Anthony Grist Commented Jun 11, 2013 at 12:34
- 1 You must wait for the popup content to be loaded before executing your script. Have a look at stackoverflow./a/3030893/1236044 – jbl Commented Jun 11, 2013 at 12:35
2 Answers
Reset to default 3Not sure it will be cross-browser, but you may try something like :
var popup = window.open("/fault_books/" + <%= @fault_book.id %> , "popup");
$(popup.document).ready(function(){
var module = $(".module-logo", $(popup.document))
// manipulating the element
$(module).hide();
});
Why don't you just put your javascript code to the generated response from "/fault_books/" + <%= @fault_book.id %>"
In that case, just do it as normal:
$(document).ready(function(){
var module = $(".module-logo")
// manipulating the element
$(module).hide();
});
And don't need to do anything when opening a new window, just call:
popup = window.open("/fault_books/" + <%= @fault_book.id %> , "popup");
This solution is simple and easier to maintain as scripts are self-contained. Scripts on a page do jobs only for the containing page. Let's say, if you have another page opening the same url window.open("/fault_books/" + <%= @fault_book.id %> , "popup");
. You don't have to duplicate code.
本文标签: How to execute javascriptjquery on a newly opened popup screenStack Overflow
版权声明:本文标题:How to execute javascriptjquery on a newly opened popup screen - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744772164a2624404.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论