SWFAddress:通过JavaScript在URL末尾添加“/”char

时间:2010-12-14 20:38:29

标签: javascript jquery url swfaddress

如何在/的末尾添加URL字符而不强制用户编写它? 我开始使用SWFAddressJavaScript直接使用jQuery Flash,而不是http://mysite.com/section // and after click to a specific <a ="#">button</a> get http://mysite.com/section/#/sub-content // instead of http://mysite.com/section#/sub-content ,如this wonderful site

这样的事情:

$(".time_dot, .time_year").click (function () {
    onClickEvent (this);
});

function onClickEvent (dom) {
    var timer = setTimeout (function () {
        SWFAddress.setValue($(dom).parent().attr("id"));
    }, 200);
    // do something else 
}

我已经开始使用此代码来执行此操作:

setTimeout

<a>方法用于避免SWFAddress.setValue按钮覆盖URL address方法,但我不知道如何将url.com/content#/...更改为{{1转到url.com/content/#/...

我该怎么做?

4 个答案:

答案 0 :(得分:2)

如前所述,您无法在不强制重新加载网站的情况下更改网址。我不认为你想要那个。 (但这取决于SWFAddress.setValue()的实际工作方式,如果只是在内部跟踪网址(不更改浏览器网址),那么就可以这样做了)

但我想为setTimeout提供替代方案:

$(".time_dot, .time_year").click (function (event) {
    event.preventDefault();
    event.stopPropagation();
    onClickEvent (this);
});

function onClickEvent (dom) {
    SWFAddress.setValue($(dom).parent().attr("id"));
    // do something else 
}

使用此功能可以防止点击事件冒泡,并防止更改默认操作(将在链接后面)。

请参阅jQuery event object

答案 1 :(得分:1)

如果不重新加载页面,则无法更改URL的“路径”部分。因此,如果您在http://mysite.com/section,则无法在不重新加载页面的情况下导航到http://mysite.com/section/#/sub-content

答案 2 :(得分:0)

你的意思是

$(".time_dot, .time_year").click (function () {
   setTimeout (function () {
         SWFAddress.setValue("/"+$(this).parent().attr("id")+"/");
    }, 200);

});

答案 3 :(得分:0)

function fixUrl(url) {  
    return url.replace(/\/?$/,'/');  
}

//or

function fixUrl(url) {  
    return url.match(/\/$/)  
       ? url  
       : url + '/';  
}