Googlebot
Googlebot

Reputation: 15683

How to make a javascript action by URL attribute?

I am playing with a very simple jquery modal windows. It opens the modal windows by clicking on

<a href="#" id="clickMe">Click Me</a>

How can I make this javascript action by adding an attribute to the URL, e.g. index.php?q=clickMe or index.html#clickMe

I mean when visiting the webpage of index.html (with q=clickMe or #clickMe), loading the page with opened modal. In other words, the attribute plays the role of CLICK on id="clickMe" for jQuery.

Upvotes: 0

Views: 116

Answers (3)

Jason
Jason

Reputation: 15931

first i would get a jquery plug in for reading querysting variables - like getUrlParam

then, you can do it in script

$(document).ready(function() {
  if ($(document).getUrlParam("activate-click").length > 0) {
    $("#clickMe").click();
  }
});

Upvotes: 1

John Hartsock
John Hartsock

Reputation: 86892

You would need to handle the QueryString or URL Hash in the document.ready(). Here is an example of handling the hash #clickMe

$(document).ready(function () {
  if (window.location.hash == "#clickMe") {
    //open modal
  }
});

Upvotes: 1

LisztLi
LisztLi

Reputation: 242

try to use jquery.url plugin.

Upvotes: 0

Related Questions