Jquery 在新窗口中打开页面并隐藏一些HTML控件
我想打开一个新窗口并在新窗口中隐藏一个div,但我无法隐藏它 下面是一个场景-Jquery 在新窗口中打开页面并隐藏一些HTML控件,jquery,html,Jquery,Html,我想打开一个新窗口并在新窗口中隐藏一个div,但我无法隐藏它 下面是一个场景- 我有一个页面“p1”和一个左侧导航栏 我想从另一个页面“p2”打开“p1”,但没有“导航栏”。我想根据条件隐藏“p1”上的导航栏 下面是我的代码 var win = window.open("p1.html", "mypage", 'width=400'); win.document.getElementById("left-sidebar").setAttribute("style", "d
var win = window.open("p1.html", "mypage", 'width=400');
win.document.getElementById("left-sidebar").setAttribute("style", "display:none;");
你知道怎么做吗?我终于找到了一种方法,下面是我是怎么做的-
<html>
<head>
<script>
</script>
</head>
<body>
Page 1
</body>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
window.open("popup.html?http://localhost/TestPage/p1.html","","");
});
</script>
</head>
<body>Page 2
</body>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
$("#iframe").attr("src", window.location.search.substring(1));
$("#iframe").load(function() {
var head = $(this).contents().find("head");
var css = '<style type="text/css">' +
'body{background-color:blue}; ' +
'</style>';
$(head).append(css);
});
});
</script>
</head>
<body>
<iframe id="iframe"></iframe>
</body>
第1页
2。P2.html
<html>
<head>
<script>
</script>
</head>
<body>
Page 1
</body>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
window.open("popup.html?http://localhost/TestPage/p1.html","","");
});
</script>
</head>
<body>Page 2
</body>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
$("#iframe").attr("src", window.location.search.substring(1));
$("#iframe").load(function() {
var head = $(this).contents().find("head");
var css = '<style type="text/css">' +
'body{background-color:blue}; ' +
'</style>';
$(head).append(css);
});
});
</script>
</head>
<body>
<iframe id="iframe"></iframe>
</body>
$(文档).ready(函数(){
打开(“popup.html”?http://localhost/TestPage/p1.html","","");
});
第2页
3。Popup.html
<html>
<head>
<script>
</script>
</head>
<body>
Page 1
</body>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
window.open("popup.html?http://localhost/TestPage/p1.html","","");
});
</script>
</head>
<body>Page 2
</body>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
$("#iframe").attr("src", window.location.search.substring(1));
$("#iframe").load(function() {
var head = $(this).contents().find("head");
var css = '<style type="text/css">' +
'body{background-color:blue}; ' +
'</style>';
$(head).append(css);
});
});
</script>
</head>
<body>
<iframe id="iframe"></iframe>
</body>
$(文档).ready(函数(){
$(“#iframe”).attr(“src”,window.location.search.substring(1));
$(“#iframe”).load(函数(){
var head=$(this.contents().find(“head”);
var css=''+
'正文{背景色:蓝色};'+
'';
$(头)。附加(css);
});
});
结果
希望它能帮助别人:)你的问题不清楚。请详细说明并提供HTML代码,以便我们可以复制问题:)可能的失败原因:CORS、文档未准备好、打字错误。但是只有你能在你的代码中检查这是“url”吗?或者有一个真实的URL?它指向我的一个页面的URL。需要将加载处理程序绑定到新窗口,以便在代码运行时元素存在。在您调用
open()