0

im looking for a way to remove the URL param after clicking the button.

The reaseon for it is i want to do something on my page on connecting if i have the url param. if not do the default thing. the problem is that if i have the param in url it will do the same thing every time i refresh the page.

my webpage contains a nav menu. on titel pressed a php file loads into the page to show something.

so the end point is if i got an param and i finished my job and refreshed the webpage, then i dont want to go there where the param takes me.

this operation should be done using JQuery or JS.

im not sure how to describe the problem more then that. comment if you got a question.

thanks for all

UPDATE

here is my code:

    const urlParams = new URLSearchParams(window.location.search);
    const myParam = urlParams.get('vertrag');

    if (typeof myParam !== 'undefined' && myParam !== null) {
    tabCaller("ver_vert_sicht", `id=${myParam}`);
    }

    function tabCaller(tabName, parameter = null) {
        //Get the current tab div id
        var current = `#nav_${$("#content").children(":first").attr("id")}`;
        
        //empty the Content Div
        $("#content").empty();
        //move the "nav_selected" class from the old nav_option to the new one
        $(current).removeClass("nav_selected");
        $(`#nav_${tabName}`).addClass("nav_selected");
        var tabUrl = `action/php/inc/${tabName}.inc.php?${parameter}`;
        console.log(tabUrl);
        
        $.ajax({
            url: tabUrl,
            success: function(data) {
                $("#content").html(data);
            }
        });  
    }

HTML:

<div id="navMenu">
    <button onclick="tabCaller('customers')">Customers</button>
    <button onclick="tabCaller('orders')">Orders</button>
    <button onclick="tabCaller('invoice')">Invoice</button>
</div>
<div id="content">

</div>
Assad Rajab
  • 69
  • 1
  • 1
  • 11
  • no. i already checked that before posting my question. i didnt get it – Assad Rajab Jul 14 '20 at 15:34
  • From your description, you need to use `.replaceState` - the linked answer shows you how to use it with multiple links to more information. It a good answer and fits your requirement. It looks like you can add, just before your `$.ajax`, `window.history.pushState({}, "", tabUrl)` (but it's not clear if that url is with or without the required param) – freedomn-m Jul 14 '20 at 16:17
  • @freedomn-m alright. Thank you for your help – Assad Rajab Jul 14 '20 at 17:15

0 Answers0