It is necessary to ensure that when the screen width is less than 1025px user flips to another page. If less, <iframe> is inserted into the current page.

Wrote, but the condition does not work:

 if (window.location.href == "такая-то ссылка").innerWidth < 1025 { $('.container').append('<iframe src="какой-то iframe"></iframe >'); } else { window.location = "на определенную страницу"; } 

How to write this line correctly: if (window.location.href == "такая-то ссылка").innerWidth < 1025 ?

  • при маштабе экрана менше 1025px, ..., если меньше, ... And what if more? - Peter Olson
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

Your condition syntax is not correct. You probably want it like this:

 if(window.location.href === "такая-то ссылка" && window.innerWidth < 1025) { $('.container').append('<iframe src="какой-то iframe"></iframe >'); } else { window.location = "на определенную страницу"; } 

    This is how it works:

     if (window.location.href == "такая-то ссылка") { $('.container').append('<iframe src="какой-то iframe"></iframe >'); if ($(window).width() < 1025) { window.location = "ссылка на другую страницу"; } } 
    • What is the point of adding <iframe> with a width of less than 1025? - Regent