www.webdeveloper.com
Results 1 to 5 of 5

Thread: how do I link an html file to a java script file

  1. #1
    Join Date
    Jul 2012
    Location
    Vantaa, Finland
    Posts
    125

    Thumbs up how do I link an html file to a java script file

    I have a mobile.js file for detecting mobile devices. The code is

    function detect_size()
    {
    if(screen.width<=650)
    {
    window.location="http://what-do-christians-believe.co.uk/mob_phone";
    exit();
    }
    if(screen.width<=995)
    {
    window.location="http://what-do-christians-believe.co.uk/mob_devices";
    exit();
    }
    if(screen.width>=996)
    {
    window.location="http://what-do-christians-believe.co.uk/book.html";
    exit();
    }

    and I have the folllowing link in my html file to link to this file;
    <script src="mobiles.js" type="text/javascript"></script>

    Either the link isn't working or I have set up the js file wrongly. Can someone show me what needs to be done to get them working.

    I have the javascript code in my html file and it works. It's just that a search engine reply to a download issue advised me to create a seperate file for the javascript as it will speed up the performance of my site.

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,653
    try to replace all the exit() with return and window.location with location.href
    Last edited by Padonak; 07-05-2012 at 12:44 PM.

  3. #3
    Join Date
    Jul 2012
    Location
    Vantaa, Finland
    Posts
    125
    Quote Originally Posted by Padonak View Post
    try to replace all the exit() with return
    Thanks for your reply. I'll give it a go.
    I'll post again if it doesn't work.

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    <script src="mobiles.js" type="text/javascript"></script>
    mobile or mobiles?

    Any console errors?

  5. #5
    Join Date
    Jul 2012
    Location
    Vantaa, Finland
    Posts
    125
    Thanks for your reply. Silly me!
    It works fine now.

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