Home > OS >  how can you check if url has parameter html
how can you check if url has parameter html

Time:02-05

So there is some issue, I am trying to do if-else statement in HTML to figure out if URL has parameter/string
I have var url and I need to check if that URL has parametr
prbly i did not explain it clearly, I need to check if website itself has string. So when you open some website and it should check if it has some word in there

                        <div  style="@style">
                            @if (url != null)
                            {
                                <a href="@url" target="_blank">@text</a>
                            }
                            else
                            {
                                <p>@text</p>
                            }
                        </div>

I tried something like if(url.inculdes('something')) but it does not work, so how can I make it works

CodePudding user response:

Select a tag using one of javascript dom selectors. and then use getAttribute('url') on that element. Then you will just have to do a simple if statement if the value is equal to null.

CodePudding user response:

You can use AlpineJs in your HTML

see this page: (https://alpinejs.dev/)

<div x-data="{ open: false }">
    <template x-if="open">
        <div>...</div>
    </template>
</div>
  •  Tags:  
  • Related