English 中文(简体)
从多个页面附加查询字符串
原标题:Appending query strings from multiple pages
  • 时间:2012-05-24 19:55:12
  •  标签:
  • javascript

我目前对此一无所知。我窥探了一下,还没有找到任何具体答案,“强烈”只用JS(JS)/强”来做这件事,所以我的问题是如此。 如果我正在浏览多个页面,并且想将查询字符串与之前连接在URL上,那么最简单的方法是什么?

最佳回答

如果用户“导航门”的方式是使用页面中的链接, 您可以做到这一点 。

  1. 在给定的 html 页面中,在页面中运行的 Javascript 可以通过 window.search 属性查看 URL s查询参数。 < a href="https:// developmenter.mozilla.org/en/DOM/window.place" rel=“nofollow” >Mozilla docs.

  2. 然后使用联署材料修改所有锁定元素 href 链接,以添加链接的现有查询参数。

结果:点击页面的链接将导致新页面既有查询参数也有新查询参数。

问题回答

我不认为有什么容易的方法。 每次您构建 URL 或创建窗体时, 您都必须考虑到当前查询参数 。

你是在问这个吗?

var url1 = "...", url2 = "...";

var query1 = url1.split("#")[0].split("?").slice(1).join("?");
if (!query1)
    return url2;
var parts2 = url2.split("#");
parts2[0] +=  (parts2[0].indexOf("?")>-1 ? "&" : "?" ) + query1;
return parts2.join("#");

这将从 url1 提取查询字符串, 并将其附加到 url2 的查询字符串, 返回新的 url2





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签