JavaScript Running Javascript via href

No, script won't run if your give someone the URL. To achive this you should check whether window.location.hash equals '#Project' on page load.

Hope this helps

Btw. what Praveen Kumar mentioned is changing your code as follow:

<ul>
    <li onclick="project()">
        <a target='_blank' href="#Project">Projects</a>
    </li>
</ul>
Answer:1

I assume you want this to work on several different anchors, so you could do something like this:

<ul>
    <li onclick="project()">
        <a target='_blank' href="#Project">Projects</a>
    </li>
</ul>

<script>
    function project() {
        alert('Function project called')
    };

    var elements = document.querySelectorAll("a[target='_blank' href='" + window.location.hash + "']")
    if (elements.length > 0)
    {
        elements[0].click();
    };
</script>

This code will make sure any hash anchor gets clicked when you navigate to the url with that hash.

Answer:2
the link will be for example "www.test.com#myproject" 
and "function project" will be run automatically

 <!doctype html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
    <script>
    function project()
    {
      alert("hello");
    }    
    </script>
    </head>
    <body>
    <div id="myproject">
        <img src="test.jpg" onload="project()">
      <a>  sample text</a>
        <p>123456789</p>
        <ul>
          <li>one</li>
          <li>two</li>
          <li>three</li>
        </ul>
    </div>
    </body>
    </html>
Answer:3

A small example

If (window.location.hash === '#Project')  {
  project() ;
}
Answer:4

I wish to animate a div to make it appear and slide down with jQuery. I have got my script to work where you hover over an image and another div slides in, should the user leave the mouse hover, the ...

I wish to animate a div to make it appear and slide down with jQuery. I have got my script to work where you hover over an image and another div slides in, should the user leave the mouse hover, the ...

I have been trying to grab json data from an API and display it using the map() function. Unfortunately the API returns data in the format: { "type": ..., "value": ... }. The second object value ...

I have been trying to grab json data from an API and display it using the map() function. Unfortunately the API returns data in the format: { "type": ..., "value": ... }. The second object value ...

  1. displaying json data in html
  2. displaying json data in react js
  3. displaying json data in angular
  4. displaying json data in html table
  5. displaying json data in php
  6. displaying json data in html using javascript
  7. displaying json data in python
  8. displaying json data in angular component
  9. displaying json data in chart js
  10. displaying json data in angular 6
  11. displaying json data
  12. displaying json data in javascript
  13. displaying json data in html using jquery
  14. displaying json data in datatable
  15. displaying json data in table
  16. displaying json data in android
  17. displaying json data in angularjs
  18. displaying json data in ionic
  19. displaying json data in jsp
  20. jquery displaying json data

Hi it is very simple question, but I didn't find the answer fit in my situation. In my jQuery dialog I have buttons which is update and close. User click 'update button' then on code behind I need ...

Hi it is very simple question, but I didn't find the answer fit in my situation. In my jQuery dialog I have buttons which is update and close. User click 'update button' then on code behind I need ...

I am attempting to pass 2 arrays to a function that filters through array 1 by array 2, then returns the filtered results. I am not understanding why I am getting the error: "Uncaught TypeError: arr2....

I am attempting to pass 2 arrays to a function that filters through array 1 by array 2, then returns the filtered results. I am not understanding why I am getting the error: "Uncaught TypeError: arr2....

  1. array some function example
  2. array some function in java
  3. typescript array some function
  4. js array some function
  5. array some arrow function
  6. php array some function
  7. angular array some function
  8. some array related functions in php
  9. array.some is not a function
  10. javascript array some arrow function