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.
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.
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.
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..
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.
<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
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>
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.
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>
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:
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