English 中文(简体)
在 Java文中选取URL
原标题:Getting URL in Javascript

Ok, I m new to Java, 在此需要一些帮助。 在一页前线/后向纽州开展工作。 基本上,该章看上去的是<编码>http://webaddress.com/details?id=27。

因此,我的两个职能是提取ur,然后向同一页推缩或加固细节,必要时,当一个 but子被点击时。 例如,有人在下顿点击id=28;如果先前点击,id=26

我认为,它有点可笑,我已经看到,它以前做了一些工作,但并不肯定做了些什么。

I need idea on how to approach it. Any help will be appreciated.

<>Update: 我使用了下文的@gion_13条代码,但像Im错sin那样。 似乎没有工作。 任何其他帮助都将受到赞赏。

最佳回答
function parseUrl(){
    if(location.href.indexOf( ? ) == -1)
        return null;
    var aux = location.href.split( ? );
     var result = {
         href  : aux[0],
         params  : {}
    };
    var p = aux[1].split( & );
    for(var i=0,l=p.length;i++)
        {
             var kv = p[i].split( = );
             params[kv[0]] = kv[1];
        }        
    return result;
}

function reconstructUrl(obj){
    if(!obj)
        return location;
    var url = obj.href +  ? ;
    for(var i in obj.params)
        url += i +  =  + obj.params[i] +  & ;
    return encodeURI(url);
}

function getNextUrl(){
    var urlObj = parseUrl();
    urlObj.id++;
    return reconstructUrl(urlObj);
}

function getPrevUrl(){
    var urlObj = parseUrl();
    urlObj.id--;
    return reconstructUrl(urlObj);
}
问题回答

您可使用<代码>所在地。

http://developer.mozilla.org/en/window.location

利用<代码>exec提取识别符号。

extracted_id = /id=([0-9]+)$/.exec(location.href)[1]

http://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/exec

  1. Read the url as var url = document.location.href
  2. Use regEx or indexOf "=" or document.location.search to find current page no
  3. Parse as int and +/- page number
  4. rebuild the the url
  5. document.location.replace(newurl)

<代码>window. place Object has the URL info You need. 你们可以使用一种reg。 这里有些提及:

查阅网页电子版,使用文件。 例如:

document.write(document.URL);

You can then modify the URL and open the new URL.

For lots of hints and tips, See JavaScript HTML DOM Examples.

You can do that without Javascript if you want. I think it s more efficient with PHP, because it will work even if some user has Javascript disabled.

You can try get the id like this:

<?php $my_id = $_GET[ id ]; ?>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签