www.webdeveloper.com
Results 1 to 2 of 2

Thread: How to use external script for hyperlink

  1. #1
    Join Date
    Aug 2013
    Posts
    1

    Post How to use external script for hyperlink

    ok i am gonna try to link in html which is through external script not direct ahref tag, so here it is,

    I have douc.html file and its coding is here,

    Code:
    <html>
    <head>
    <title>Title of the document</title>
    </head>
    
    <body>
    The content of the document......</p>
    The <a href="http://sitelink.com">link</a> of the document ......
    </body>
    
    </html>
    This HTML page use ahref tag for hyperlink ....

    I want to use external script where the hyperlink is hosted (in script file)and it display here in html page when it loads, how i do that, ????????

    Any question will preferred to answer

  2. #2
    Join Date
    Mar 2009
    Posts
    512
    If I understand your question correctly you can do something like this:

    Code:
    // have a file on your server (I'll call it link.js) that simply reads:
    //var myLink = "http://somePlace.com";
    
    //then:
    <html>
    <head>
    <script type="text/javascript" src="link.js">
    </script>
    <script type="text/javascript">
    
    window.onload= function(){
      var z = document.getElementById('a1');
      z.href = myLink;
    	  
    }
    
    </script>
    </head>
    <body>
    <a id="a1">This is a link</a>
    
    </body>
    <html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles