views:

37

answers:

3

At first I would like to point out, that I am not a JQuery person, I am just beginning my work with it forced by the fact that our front-end guy is sick. please be delicate with me:)

In our application we switch to view mode by changing part of the url:

  • .../view/rest/.... means normal mode,
  • .../print/rest/... means print mode (site is stripped, different CSS applied).

I would like to check in javascript in which mode I currently am. We use JQuery in out project.

Please help!

+2  A: 

Do a simple string search on window.location.pathname:

var isPrint = window.location.pathname.indexOf("/print/") > -1;
  • /view/rest
    alert(isPrint); // -> false
  • /print/rest
    alert(isPrint); // -> true

You can also perform a split and check a specific subfolder:

var folders = window.location.pathname.split("/");
var isPrint = folders[1] == "print";
Andy E
+1  A: 

You can examine the current URL by referencing location.href in your JavaScript code and determine it that way (no jQuery required).

inkedmn
A: 

You could use

var inPrint = (document.URL.indexOf("/print/") != -1);

(as long as there are no other /print/ folders)

James Westgate