-2

i wish to add a further action to the script to change the css for a class

document.write( 'DIV STYLE='display;none;); />' ) } was my initial idea but it doest seem to work so using

    if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) {
document.write( '<base target="_blank" />' );
     }

and adding to it with

    if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) {
document.write( '<base target="_blank" />' ); document.write( 'DIV STYLE='display;none;); />' ) 
    }

the body is

     <div class="headerlogo"> Serious Photography </div>
     <div> Serious Photography 2 </div>
leepowers
  • 35,484
  • 22
  • 93
  • 127
  • So you want to add a style to make .headerlogo display:none? – danronmoon Jan 30 '13 at 20:35
  • only when on the location is if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) – Matthew Kelly Jan 30 '13 at 20:41
  • @MatthewKelly Why don't you use different html page? – Yair Nevet Jan 30 '13 at 20:49
  • its for modifying a third party shop image sales solution page - in some cases i want the links to open in a new window - by default they open in the same window - they used to open in a new one - and i have the collection page as a 200px high letterbox so the if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) { document.write( '' ); i want a header to appear in all cases apart from when it is in a letterbox so i wish to add a hide .headerlogo via display:none; to all the scenarios in the above link – Matthew Kelly Jan 30 '13 at 21:44
  • in then end I went with and it is working perfectly – Matthew Kelly Jan 30 '13 at 22:06

2 Answers2

0

This is kind of a hard question to follow, but if you want to check for what page you are on, you can use

window.location.href 

A conditional check to match the strings could then decide whether you want to add the new style. I'd change the class to an ID.

then you can do

document.getElementById('headerlogo').style.display = 'none';

Personally, I'd use SIZZLE or jQuery to make the selectors easier.

$('.headerlogo').css('display', 'none');
  • Yeah.. That's why I added the caveat, I'd change to an ID in this example or use SIZZLE. Forgot to add it in my original post. You could use getElementsByClassName, but only if you aren't supporting lt IE8 – Daniel Beacham Jan 30 '13 at 20:52
  • ok how do i add it to if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) { document.write( '' ); doesn't seem to work } doing – Matthew Kelly Jan 30 '13 at 21:52
  • thanks for the help went with instead but i would use jquery but limited in what i can do as modifying a third party website with non linking embedding allowed :( – Matthew Kelly Jan 30 '13 at 22:05
0

Please avoid using document.write. Here's a link that explains why. Your argument for indexOf contains invalid syntax, as well. HTML base also has nothing to do with applying styles, and 'DIV STYLE='display;none;); />' is incorrect HTML/CSS syntax, and would have no effect in applying styles to your headerlogo class, either.

This is useful for adding a style tag to classes and ids that may not exist yet.

if (location.href.indexOf(
       "/smispage/tpfpage/client_images_new/client_images_list") > -1
) {
    var style = document.createElement('style');
    style.type = 'text/css';
    style.appendChild(document.createTextNode('.headerlogo{display:none;}'));
    document.getElementsByTagName('head')[0].appendChild(style);
}
Community
  • 1
  • 1
danronmoon
  • 3,613
  • 5
  • 32
  • 55
  • seems to work so thank you very much – Matthew Kelly Jan 30 '13 at 22:04