0

I am trying to load a src url inside of javascript, but its not working..

function detectmob() {
   if(window.innerWidth <= 800 && window.innerHeight <= 600) {     
    return 'https://example.com/advertisements.js';   
   } else {

    return false;

   }
}
Dave
  • 89
  • 6

2 Answers2

1

Can't you just add this in the html and define the js file you want to load? For example:

<script>
if (screen && screen.width <= 800 && screen.height <= 800) {
  document.write('<script type="text/javascript" src="foo.js"><\/script>');
}
</script>
lacostenycoder
  • 10,623
  • 4
  • 31
  • 48
0

You don't need to return anything to change the window location. Instead of return you can use: window.location = newUrl;

Paul Hoke
  • 115
  • 2
  • 7