Source language: Translate to:

How to change style on the fly ?

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

How to change style on the fly ?

Postby David de Argentina » Mon Oct 26, 2015 1:54 pm

Hi all,

My NeoBook program load into an WebBrowser object a html file.
The html file has this style:

Code: Select all
  <style type="text/css">
    .iconfree {
      background-image: url('Pin_Violet2.png');
      text-align: center;
      color: White;
      font: arial, sans-serif;
      font-size: 14px;
      font-weight: bold;
    }
  </style>


I need change the color attribute (or another one) on the fly.

This action works fine at Chrome, FF, Opera... and IE9 or newer.
Code: Select all
BrowserExecScript "NavegadorWeb1" "document.getElementsByClassName('iconfree')[0].style.backgroundImage = 'url(Pin_Blue2.png)';" "JScript"


IE8 (browser component for Win XP) does not support getElementsByClassName method.

I need XP users can use this program.

Does any know how to change (via javascript or something else) this style on the fly and still work on IE8 ?

Thanks in advance,

David de Argentina
User avatar
David de Argentina
 
Posts: 1553
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: How to change style on the fly ?

Postby David de Argentina » Mon Oct 26, 2015 4:01 pm

Jquery does the job.

Greetings !
David de Argentina
User avatar
David de Argentina
 
Posts: 1553
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: How to change style on the fly ?

Postby Gaev » Mon Oct 26, 2015 4:11 pm

David de Argentina:

Yes, you can use jQuery ... but if this was the only reason for adding jQuery to your Application, you can consider these alternatives ...

1) This webpage ... http://stackoverflow.com/questions/6584 ... -ie6-ie7-i ... proivdes a solution.

2) Consider naming each element (id='1', id="2" etc. etc.) in your html ... then, you can select an element with something like ...

getElementById("7")

... which is supported by older Browsers as well.


BTW, for the benefit of others who seek similar solutions, post your jQuery code here.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: How to change style on the fly ?

Postby David de Argentina » Mon Oct 26, 2015 5:11 pm

Thanks Gaev,

But all elements were created using Javascript.
No ID or tag to search them normally.

Greetings,
David de Argentina
User avatar
David de Argentina
 
Posts: 1553
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: How to change style on the fly ?

Postby Tony Kroos » Mon Oct 26, 2015 9:50 pm

So you don't have access to js code and cannot modify it?
David de Argentina wrote:No ID or tag to search them normally.

You always do have tags at runtime, otherwise it would not be a valid html document. Search google for "traversing DOM tree" and "parent/child elements".
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest