[英]On Click: Open a Pop-up Div on a Different Page
On page1.php I have a click
event that causes the user to be redirected to page2.php. 在page1.php上我有一个
click
事件,导致用户被重定向到page2.php。 It goes something like this: 它是这样的:
$("#someButton").click(function() {
window.location = "page2.php";
});
And that works great. 这很有效。 But what I really want is to open a hidden, UI-blocking
<div>
on page2. 但我真正想要的是在第2页上打开一个隐藏的,阻止UI的
<div>
。 The user can already open this <div>
manually by clicking another button on page2, that goes something like this: 用户可以通过单击第2页上的另一个按钮手动打开此
<div>
,如下所示:
$('#someOtherButton').click(function() {
$("#pageContainer").block({message: $("#theDivIWant2See")});
});
Can I make a click
event from the JavaScript on one page call the JavaScript on another? 我可以在一个页面上从JavaScript中创建一个
click
事件,在另一个页面上调用JavaScript吗? Or will I need to add in some HTML-parsing to pass information between pages? 或者我是否需要添加一些HTML解析来在页面之间传递信息? (I'm not looking for a JavaScript hand-out here, just a strategy to help me move forward.)
(我不是在这里寻找一个JavaScript手册,只是一个帮助我前进的策略。)
When you redirect from the first page, add a querystring value in your url. 从第一页重定向时,在网址中添加查询字符串值。 and in the second page, using your server side page language, set in in a hidden field and in the document ready event check the value of that hidden field.
在第二页中,使用服务器端页面语言,在隐藏字段和文档就绪事件中设置,检查该隐藏字段的值。 If the value is expected, call a javascript function to show the popup.
如果值是预期的,请调用javascript函数以显示弹出窗口。
Some thing like this 有点像这样
$("#someButton").click(function() {
window.location = "page2.php?showpopup=yes";
});
and in page2.php set it (forgive for errors, i am not a php guy) 并在page2.php设置它(原谅错误,我不是一个PHP人)
<input type='<?php $_GET["showpopup"] ?>' id='hdnShow' />
and in the script 并在脚本中
$(function(){
if($("#hdnShow").val()=="yes")
{
//Call here the method to show pop up
}
});
You need to do your stuff when DOM for page2 is ready. 当第2页的DOM准备就绪时,你需要做你的事情。 You can use jQuery's ready function for that.
你可以使用jQuery的ready函数。
$(document).ready(function() { // put code for showing your div here });
$(document).ready(function(){//放置代码以显示你的div});
Hope that helps. 希望有所帮助。
Could you pass a query string argument or assign a cookie that the other page could then check when the document loads? 您是否可以传递查询字符串参数或指定另一个页面可以在文档加载时检查的cookie? If the value exists then present a modal dialog (eg jQuery UI Modal Popup)
如果该值存在则呈现模态对话框(例如jQuery UI Modal Popup)
http://jqueryui.com/demos/dialog/ http://jqueryui.com/demos/dialog/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.