【问题标题】:How do I successfully append a string to a url in a bookmarklet without it repeating?如何在不重复的情况下成功地将字符串附加到书签中的 url?
【发布时间】:2016-10-06 18:32:17
【问题描述】:

我有以下 javascript 代码用作书签。它运作良好,但似乎我多次附加字符串 'e?nooverride=1' 。我只想替换字符串一次。

这里是网址:https://c.cs24.visual.force.com/apex/page1?id=0061A00001386pX 这是所需的网址:https://c.cs24.visual.force.com/apex/page1?id=0061A00001386pX

这是我的代码:

var urlString = window.location.href;
if(urlString.includes("apex/page1?id=")){
    urlString = urlString.replace("apex/page1?id=", "");
}

else if(urlString.includes("apex/page2?id=")){
    urlString = urlString.replace("apex/page2?id=", "");
}

if(urlString.includes("&sfdc.override=1")){
    urlString = urlString.replace("&sfdc.override=1", "");
}

window.location.href=urlString+'/e?nooverride=1';

【问题讨论】:

    标签: javascript bookmarklet window.location


    【解决方案1】:

    代码运行良好。我显然在使用后退/前进浏览器按钮,这与存储在 url 中的内容混淆了。

    【讨论】:

    • 你应该关闭/删除问题。
    猜你喜欢
    • 2019-04-14
    • 2019-10-12
    • 2020-08-04
    • 1970-01-01
    • 2023-03-20
    • 2018-03-11
    • 2019-08-24
    • 2017-06-25
    • 1970-01-01
    相关资源
    最近更新 更多