1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to Insert Javascript in index.php file

Discussion in 'JavaScript' started by muzzy4u2, Aug 27, 2011.

  1. #1
    Hi,

    I want to insert javascript code in index.php. Head section..

    But there is no title,head,body in this file.

    I want to add javascript code in the head section so that when user access my site via mobile they can see mobile version of my site.

    site is mobilewebsitex[dot]com

    I am using wordpress for this site

    so please help me.
     
    muzzy4u2, Aug 27, 2011 IP
  2. iBank ™

    iBank ™ Peon

    Messages:
    63
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You should be looking at your theme files, not Wordpress core.
     
    iBank ™, Aug 31, 2011 IP
  3. muzzy4u2

    muzzy4u2 Active Member

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #3
    I have inserted the code in header.php file.

    This is the code given by gomobi.I have tried inserting this code but its not working.
    <script type="text/javascript" src="http://detect.deviceatlas.com/redirect.js?d=http://mobilewebsitex.com&m=http://GM26915.gomobinow.mobi"></script>

    So I have tried this code
    <script type="text/javascript">
    <!--
    if (screen.width <= 700) {
    document.location = "http://mobilewebsitex.com&m=http://GM26915.gomobinow.mobi/";
    }
    //-->
    </script>



    <script language=javascript>
    <!--
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
    location.replace("http://mobilewebsitex.com&m=http://GM26915.gomobinow.mobi/");
    }
    -->
    </script>

    But none of the code is working i.e. the site is not redirecting to mobile version when I am accessing via mobile.
     
    muzzy4u2, Aug 31, 2011 IP
  4. iBank ™

    iBank ™ Peon

    Messages:
    63
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Are you sure your mobile phone supports Javascript ? The code you posted works just fine.
     
    iBank ™, Aug 31, 2011 IP
  5. muzzy4u2

    muzzy4u2 Active Member

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #5
    NO I dont have I phone I am testing it online @

    iphonetester dot com and its showing same old version i.e.pc version of my site.
     
    muzzy4u2, Aug 31, 2011 IP
  6. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #6
    iphonetester doesn't really mimic iphone browsing it just making your site contained in an iframe with a small width..

    it's better to really test it in an iphone or ipod..
     
    JohnnySchultz, Sep 1, 2011 IP
  7. muzzy4u2

    muzzy4u2 Active Member

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #7
    Its working now I have downloaded addon plugin i.e. user-switch-agent for firefox and activated it.now when I am typing my site in the browser its redirecting to the mobile version.
     
    muzzy4u2, Sep 1, 2011 IP
  8. HalvinCarris

    HalvinCarris Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Great job :)
     
    HalvinCarris, Sep 3, 2011 IP
  9. articlesdirectory

    articlesdirectory Greenhorn

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #9
    <script type="text/javascript" language="javascript">
    <!--
    your javascript code here
    //-->
    </script>

    This will work.
    If this not works then enable javascript of your internet browser.. if it remains same then make settings of your server
     
    articlesdirectory, Sep 5, 2011 IP
  10. akumar2

    akumar2 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    great.. thanks :)
     
    akumar2, Sep 20, 2011 IP
  11. amherstsowell

    amherstsowell Peon

    Messages:
    261
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    This is the one way to include JS in your PHP file

    <?Php

    ---------
    ---------

    ?>

    <html>
    <body>
    <script type="text/javascript" language="javascript">
    <!--
    your javascript code here
    //-->
    </script>
    </body>
    </html>
     
    amherstsowell, Sep 20, 2011 IP
  12. ssovan

    ssovan Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    great post thank u, help me lot
     
    ssovan, Sep 21, 2011 IP
  13. developer.designer

    developer.designer Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Check header.php in wordpress and post there
     
    developer.designer, Oct 8, 2011 IP
  14. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #14
    Just so you know for the future, header and head are totally different things. Putting something in a file named header.php almost guarantees that it won't be in the head of the document.
     
    Rukbat, Oct 24, 2011 IP
  15. g1948

    g1948 Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    lol..... :rolleyes:
     
    g1948, Oct 25, 2011 IP
  16. nicemanitaly

    nicemanitaly Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    i am trying to insert a javascipt on a php page :

    how can i do this ?

    the code is :
    <script type="text/javascript">try{var qs = window.location.search.substring(1);document.write(unescape("%3Cscript src='http: ?" + qs + "&lang=en' type='text/javascript'%3E%3C/script%3E"));}catch(err) {}</script>
     
    nicemanitaly, Nov 16, 2011 IP
  17. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #17
    just insert it outside the PHP tags.
    
    <?php
    //your php stuiff
    ?>
    <script type="text/javascript">
    try{
      var qs =  window.location.search.substring(1);
      document.write(unescape(""));
    }
    catch(err) {}
    </script>
    <?php
    ...
    
    PHP:
     
    Rukbat, Nov 16, 2011 IP
  18. nicemanitaly

    nicemanitaly Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Thanks Rukbat.

    Is there anyway , that i can assign my script to an image , so that on clicking it opens in a new window !!

    when i inserted the script outside php code , its not visible ???

    Thanks
     
    nicemanitaly, Nov 16, 2011 IP