简体   繁体   English

用Javascript加载页面

[英]Loading a Page with Javascript

I have a function in a floatbox like this: 我在这样的floatbox中有一个函数:

parent.fb.resize( {left: -360, width: true, height:true }, function () {
    parent.location.reload( true );
}, 0.7 );

Ignore the fb.resize which is part of Floatbox. 忽略Floatbox中的fb.resize。 It's the callback function 这是回调函数

parent.location.reload( true );

which I'm trying to improve upon. 我正在努力改进。 The function reloads the parent page from the server, and a PHP session variable controls the content of the parent page. 该函数从服务器重新加载父页面,PHP会话变量控制父页面的内容。

The problem I have is that the address bar only shows www.mywebsite.com/ so the user can't copy it as a link. 我的问题是地址栏仅显示www.mywebsite.com/,因此用户无法将其复制为链接。 Instead I would like it to show www.mywebsite.com/mypage.php?parameter=something. 相反,我希望它显示www.mywebsite.com/mypage.php?parameter=something。 So I need the callback function to send the parameter with a GET, instead of relying on the seesion variable/ But, how? 因此,我需要回调函数来使用GET发送参数,而不是依赖于seesion变量/但是,如何?

I solved it in the way num8er suggested. 我以num8er建议的方式解决了它。 The callback function became 回调函数变为

parent.window.history.pushState(null, null, "mypage.php?parameter=<?php echo $_SESSION['something'] ?>");
parent.location.reload( true );

Then because there are times when the session parameter has not been set, I expanded it to 然后,由于有时没有设置session参数,我将其扩展为

<?php if (isset($_SESSION['something'])) { ?>
parent.window.history.pushState(null, null, "mypage.php?parameter=<?php echo $_SESSION['something'] ?>");
parent.location.reload( true );
<?php }else{?>
parent.location.replace( "http://www.mywebsite.com/mypage.php" );
<?php }?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM