Tyler
Tyler

Reputation: 31667

See if certain text is in URL and if so print something dynamically via javascript

Here is what I would like to ideally do within my HTML - I would like to insert a bit of javascript that checks to see if a certain directory name is listed in the current user's URL and if so, output copy on the page. For example:

If the current URL has the word "trigger" in it such as:

http://www.mysite.com/pages/trigger/dosomestuff.html

then I want to output "confirmed" on the page.

I am not too familiar with javascript, so I am hoping that someone can help!

Thanks!

Upvotes: 0

Views: 49

Answers (1)

Byron Whitlock
Byron Whitlock

Reputation: 53901

if (location.href.match("trigger"))
{
    document.write("<h1>confirmed!</h1>")
}

Upvotes: 1

Related Questions