Passing url parameters to webpart in SharePoint

Passing url parameters to webpart in SharePoint


To pass the URL parameters to a webpart page in SharePoint, we cant use the "Page Viewer" webpart because it does not allow us to use the parameters in the URL.


So we use teh "Content Editor" webpart since it allows us to embed javascript code in it. We can then use an "iframe" with a generated URL from a JavaScript with URL parameters from the webpart pages URL.

First, create a webpart page, then insert a content editor webpart in it with the following code:

<script type="text/javascript">

    function getQueryStringRegExp(name) {

        var reg = new RegExp("(^|?|&)"

+ name + "=([^&]*)(s|&|$)", "i");

        if (reg.test(location.href))

return unescape(RegExp.$2.replace(/+/g, " "));

        return "";

    }

    document.write("<iframe src=http://www.sitename.com/default.aspx?param1="+ getQueryStringRegExp(param1) + " width=100% height=100%></iframe>");

</script>


The function getQueryStringRegExp is used to retrieve the parameter value from the page url.


Referece:

http://www.codebit.cn/pub/html/javascript/tip/javascript_get_url_parameter/





go to link download

Popular posts from this blog

DroidJack RAT Androrat Android Sample

Modern Combat 2 Black Pegasus apk data Free Download

Notepad 6 6 8