0

i made a html page with this coding

<html>
<head>
<script src="../a.js">
var u=document.URL; var i='t4527878445'; m_web(u,i);
</script>
</head>
<body>
</body>
</html>

In a.js i have this code

function m_web(u,i) {
    alert('l');
    alert('u');
}

but my webpage is unable to call this function which is coded in an external file. i am not getting any alert with this. i don't know what is problem. plz tell me simple solution for this. thanx in advance

3 Answers 3

3

A single <script> tag can link to an external resource using the src attribute OR contain inline JavaScript code, but it can't do both at the same time. If you specify a src attribute any content between the <script src="foo.js"> tag and the </script> tag is ignored.

Since you want to load the external JS file, and then execute some JavaScript code, you'll need two separate tags to do so:

<script src="../a.js"></script>
<script>
    // your code
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

plz write your code like below

<script src="../a.js"></script> </script>
   //^^^^^^^^^^^^^^^^^^ first close script tag of linked js file
<script type="text/javascript">// then call your inline jscode
var u=document.URL; var i='t4527878445'; m_web(u,i);
</script>

Comments

1

Try

you are not closing script tag

<script src="../a.js"></script>
                       ^//added closing script tag
<script>
var u=document.URL; var i='t4527878445'; m_web(u,i);
</script>

to alert what you pass use

function m_web(u,i) {
    alert(i);
    alert(u);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.