【问题标题】:Get url from query string and load it in div [closed]从查询字符串中获取 url 并将其加载到 div [关闭]
【发布时间】:2014-01-09 15:52:47
【问题描述】:

我正在设计一个简单的ASPX 页面,它有两个div's。第一个 div 具有静态内容。第二个我想要动态的内容。我希望用户在查询字符串中提供 URL,并且我需要在我的第二个 div 中显示该 URL。到目前为止,我已经做到了。

Index.aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Frames Example</title>
    <script type="text/javascript">
        function LoadQueryPage() {
            var str = <%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Request.QueryString["pagename"]) %>

            $("#siteloader")
            .html('<object data=' + str + '/>');
        }
    </script>
</head>
<body>
    <div style="min-height: inherit; height: 100px;">
        Farhan S. Mukadam
    </div>
    <div> 
    <object type="text/html" data="http://validator.w3.org/" width="800px" height="600px" style="overflow:auto;border:5px ridge blue">
    </object></div>
</body>
</html>

但这不起作用。有人可以帮忙吗?

【问题讨论】:

  • this is not working...错误是什么...??
  • 它从 Querystring 中获取值。我不确切知道。我从某个地方得到了这个 JS 代码。
  • GetParameterValues的实现在哪里
  • 这是我的第二个代码。最初我有一些其他的代码。我会发布它。
  • 错误是我的第二个 div 没有打开我在查询字符串中提供的 URL。

标签: javascript jquery html asp.net query-string


【解决方案1】:

试试

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
<script>
    $(function () {
        var pagename = GetParameterValues('pagename');
        $('#siteloader').load(pagename);
    }); //missing ) here
    function GetParameterValues(param) {
        var regex = new RegExp('(\\?|&)' + param + '=(.*?)()(&|$)')
        return location.href.match(regex)[2];
    }
</script>

另外你还没有在页面中包含 jQuery

【讨论】:

  • 没有成功。我只能看到第一个 div。第 2 个 div 中没有内容。
  • @FarhanMukadam 控制台中的任何其他错误
  • @FarhanMukadam 查看更新
  • 没有错误。我只能看到“Farhan S. Mukadam”。当我传递此查询字符串localhost:60877/Index.aspx?pagename=http://www.asentechll.com 时,第二个 div 不会显示我指定的站点。就像在我的示例“www.asentechllc.com”中一样。也包括 jquery。
【解决方案2】:
function GetRequestParameters(name) {
    if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(location.search))
        return decodeURIComponent(name[1]);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多