开发者

Pop-Up Window on page load

开发者 https://www.devze.com 2023-03-07 15:34 出处:网络
I need to have a pop-up window displayed when a page loads.What\'s happening is this.After an order is placed the user is redirected to their index page (main log-in page for the account)when they are

I need to have a pop-up window displayed when a page loads. What's happening is this. After an order is placed the user is redirected to their index page (main log-in page for the account) when they are redirected to the index page, I need a pop-up window to display on the page load that says something like "Your order for $variable has been saved". The $variable is defined on the previous page (where they are coming from) and I need that to carry over so I can display it in the pop-up box. Then once they click on "Ok" in the pop-up box, they are at the main page like always.

I have used a java popup box before on this project, but I am unsure of how to do one with these requirements. If there are any other/better ways to do this I am open to ideas. The layout of how this needs to work i开发者_C百科s below:

Client is logged into their account -> Order.php Page (Place an order) -> redirected to their member-index.php page (Pop-up needs to load on page load, and only when it comes from the order.php page)

Thanks!


Well from what I understand this would be the best match for you.

On previous page save a cookie (source http://www.quirksmode.org/js/cookies.html).

function createCookie(name,value,days) {
if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}

createookie("prevData", prevData, 30);

Then on the page you want the popup to appear (I suggest using an alert) (Note: you need the cookie code available on this page as well):

var prevData =  readCookie("prevData");
if(prevData != null){
    alert("Your order for " + prevData + " has been saved");
    eraseCookie("prevData");
}

this could be in <body onLoad="code"> or simply a script in the header or anywhere really.


You can't force a popup page to open upon page load; browsers won't do that anymore. You can create a "fake" popup window by just positioning an element in the middle of the screen and decorating it so that it looks kind-of like a window. Various JavaScript libraries provide such "dialog" facilities.


` function showpopup() {

            var findString = /order.php/gi;
            var referringURL = document.referrer;
            var data = getQuerystring('variable');
            if(referringURL.match(findString)) {
                var windowprops = "left=50,top=50,width=500,height=500";
                var preview = window.open("http://google.com", "preview", windowprops);
                preview.document.write(data);
            } else {
                alert("Not order.php "+data);
            }
        }

        function getQuerystring(key, default_) {
            if (default_==null) default_="";
            key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
            var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
            var qs = regex.exec(window.location.href);
            if(qs == null)
                return default_;
            else
                return qs[1];
        }
    </script>
</head>
<body onload="showpopup()">

`


I assume you mean javascript. You may want to do this

<body onLoad="popup()">

Any code in the "onLoad" event should fire once the html is loaded. If you are using Jquery, it should look like this

$("document").ready(function() {
    popup();
});

You can pass your variable into the popup function.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号