开发者

How to get URL from an overlay if the webpage was shown in an overlay

开发者 https://www.devze.com 2023-03-23 04:42 出处:网络
I have a search page. Now i wanted to open the search page when the user clicks on a certain link. Now i do some query search ,select some filter so as i proceed the new parametrs are added to the url

I have a search page. Now i wanted to open the search page when the user clicks on a certain link. Now i do some query search ,select some filter so as i proceed the new parametrs are added to the url.

For example when I do search for "club" query in google search I see the following url.

     http://www.google.com/#sclient=psy&hl=en&source=hp&q=club&pbx=1&oq=club&aq=f&aqi=g5&aql=&gs_sm=e&gs_upl=257848l258668l2l259633l5l4l0l0l0l3l462l1655l3-1.3l4&bav=on.2,or.r_gc.r_pw.&fp=aeb16183bfd07c66&biw=1280&bih=628

Now i filter my search and select image filter from the left side options my url look like the following

    http://www.google.com/search?q=club&hl=en&biw=1280&bih=628&prmd=ivnsm&source=lnms&tbm=isch&ei=_4wwTsvfNdDQsgac0cz0Dw&s开发者_运维知识库a=X&oi=mode_link&ct=mode&cd=2&ved=0CBAQ_AUoAQ

Now i want to put my search page in an overlay. And then when the user is done with all search he can click "OK" button on bottom right of the overlay . So when the user clicks "OK" i want the URL which is generated when the search page normally opens up in tab window like the one shown above for google case.


An overlay (or a modal overlay in the example you've provided) for a separate site can be accomplished using JavaScript, css, and an iframe.

If you are interested in using an existing library, jQuery ui has a very nice overlay they call the dialog. http://jqueryui.com/demos/dialog/

If you don't want to use a library then you have to do something similar to the following code. Note: This code is very basic and doesn't provide many features available by using a library that handles overlays.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
    <script language="javascript" type="text/javascript">

    //Define a class to create and control the overlay
    function overlay(width, height) {

        var container, iframe;

        this.setLocation = function(url) {
            iframe.setAttribute('src', url);
        }

        this.getLocation = function(url) {
            return iframe.getAttribute('src');
        }

        this.show = function() {
            container.style.display = 'block';
        }

        this.hide = function() {
            container.style.display = 'none';
        }

        function windowSize() {
            var winW = 630, winH = 460;
            if (document.body && document.body.offsetWidth) {
                winW = document.body.offsetWidth;
                winH = document.body.offsetHeight;
            }
            if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) {
                winW = document.documentElement.offsetWidth;
                winH = document.documentElement.offsetHeight;
            }
            if (window.innerWidth && window.innerHeight) {
                winW = window.innerWidth;
                winH = window.innerHeight;
            }
            return [ winW, winH ];
        };

        (function() {
            //create the containing element
            container = document.createElement('div');
            container.style.position = 'fixed';
            container.style.top = '0px';
            container.style.left = '0px';
            container.style.right = '0px';
            container.style.bottom = '0px';
            container.style.zIndex = 1000;
            container.style.backgroundColor = 'rgba(0, 0, 0, .5)';

            //create the iframe
            iframe = document.createElement('iframe');
            iframe.setAttribute('frameborder', 0);
            iframe.style.position = 'absolute';
            iframe.style.width = width + 'px';
            iframe.style.height = height + 'px';
            iframe.style.left = ((windowSize()[0] - width) / 2) + 'px';
            iframe.style.top = ((windowSize()[1] - height) / 2) + 'px';

            container.appendChild(iframe);
            document.body.appendChild(container);
        })(this)

    }

    //create an overlay object, set it's location, and show it
    var win = new overlay(700, 400);
    win.setLocation('http://www.google.com/');
    win.show();

    </script>
</body>
</html>
0

精彩评论

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