There extension shows content on my site and I want to block it using JavaScript. Is there anyone that knows how to block these div classes from being created?
Try This Code:
function Init () {
var body = document.body;
if (body.addEventListener) {
body.addEventListener ('DOMNodeInsertedIntoDocument', OnNodeInsertedIntoDocument, false);
}
}
function OnNodeInsertedIntoDocument () {
var elements = ["mainPouchDiv", "pouchNotifyHeader", "nsPouchCrossPromotionContainer"];
var element = null;
var i = 0;
for (i = 0; i < elements.length; i++) {
element = document.getElementById(elements[i]);
if (element) {
document.body.removeChild(element);
element = null;
}
}
}
Related
Trying to figure out onmouseover, onmouseout and onclick with several pictures all having the same ID tag. To do that, I understand I need a .length loop.
This code works without the length loop...
window.onload = setPictures;
function setPictures() {
var img = document.getElementById("pictureBox");
img.onmouseover = mouseOverImage;
img.onmouseout= mouseOutImage;
}
function mouseOverImage() {
var img = document.getElementById("myImg");
img.style.opacity = .5;
}
function mouseOutImage() {
var img = document.getElementById("myImg");
img.style.opacity = 1;
}
This is the loop function I attempted that is not working.
window.onload = setPictures;
function setPictures() {
var img = document.getElementById("pictureBox");
for (var i=0; i<img.length; i++) {
img[i].onmouseover = mouseOverImage;
img[i].onmouseout= mouseOutImage;}
}
Please advise, and thank you in advance for your help!
getElementById only returns one element, as ID's should be unique.
Instead, add a class to each element and select them by class. Callbacks can rely on this's context for your mouse events:
function mouseOverImage() {
this.style.opacity = .5;
}
function mouseOutImage() {
this.style.opacity = 1;
}
window.onload = function setPictures() {
var imageCollection = document.getElementsByClassName('pictureBox');
for (var i=0; i < imageCollection.length; i++) {
imageCollection[i].onmouseover = mouseOverImage;
imageCollection[i].onmouseout = mouseOutImage;
}
}
As it has been said, getElementById return only one element.
This below could help you:
window.onload = setPictures;
function setPictures() {
var img = document.getElementById("pictureBox0");
for (var i=1; img != null; i++) {
img.onmouseover = mouseOverImage;
img.onmouseout= mouseOutImage;
img = document.getElementById("pictureBox"+i);
}
}
I need to disable a section if a value from other field is true, normally I would do:
function disableSection1(disabledStatus){
Xrm.Page.getControl("section1field1").setDisabled(disabledStatus);
Xrm.Page.getControl("section1field2").setDisabled(disabledStatus);
Xrm.Page.getControl("section1field3").setDisabled(disabledStatus);
Xrm.Page.getControl("section1field4").setDisabled(disabledStatus);
}
but i have to do this for many sections, so I am looking for a function like this:
function sectionSetDisabled(tabNumber, sectionNumber, disabledStatus){
//some code..
}
Most answers I have seen you have use the use the sectionLable and do the following comparison:
controlIHave.getParent().getLabel()=="name of the section
But after some trials I found I could use Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber).controls.get() to get the controls inside the section. That allowed me to use the following function:
function sectionSetDisabled(tabNumber, sectionNumber, disablestatus) {
var section = Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber);
var controls = section.controls.get();
var controlsLenght = controls.length;
for (var i = 0; i < controlsLenght; i++) {
controls[i].setDisabled(disablestatus)
}
}
by using controls[i].getAttribute() you can then get the attributes of a section.
I ended up creating a object that allows me to disable and clear all the fields in a section:
function sectionObject(tabNumber, sectionNumber) {
var section = Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber);
this.setDisabled = function (disablestatus) {
var controls = section.controls.get();
var controlsLenght = controls.length;
for (var i = 0; i < controlsLenght; i++) {
controls[i].setDisabled(disablestatus)
}
};
this.clearFields = function () {
var controls = section.controls.get();
var controlsLenght = controls.length;
for (var i = 0; i < controlsLenght; i++) {
controls[i].getAttribute().setValue(null);
}
};
}
var section=new sectionObject(0,1);
section.setDisabled(true/false);
function TabObject(tabName, DisableStatus) {
var sectionName = Xrm.Page.ui.tabs.get(tabName).sections.get();
for (var i in sectionName) {
var controls = sectionName[i].controls.get();
var controlsLenght = controls.length;
for (var i = 0; i < controlsLenght; i++) {
controls[i].setDisabled(DisableStatus);
}
}
}
In CRM 2013 (and later), you can use the forEach iterator. This essentially allows the functionality in a one-liner.
/* Parameters:
* tabNumber = Tab Name/Id assigned in the form editor.
* sectionNumber = Section Name/Id assigned in the form editor.
*/
function sectionSetDisabled(tabNumber, sectionNumber, disabledStatus) {
// Pull the tab, then section (within the tab) and create an iterator.
Xrm.Page.ui.tabs.get(tabNumber).sections.get(sectionNumber).controls.forEach(
// Delegate to set the status of all controls within the section.
function (control, index) {
control.setDisabled(disabledStatus);
});
}
Check following article that provides code - http://blogs.msdn.com/b/crm/archive/2011/09/29/disable-all-fields-in-a-section-based-on-the-value-of-another-field-crm-2011.aspx
I'm new to programming. I just want to know, how do I highlight the current chapter while playing the video on the chapter menu of the youtube chapter marker player.
Live link : http://gdata-samples.googlecode.com/svn/trunk/ytplayer/ChapterMarkerPlayer/index.html
Full CSS : http://gdata-samples.googlecode.com/svn/trunk/ytplayer/ChapterMarkerPlayer/chapter_marker_player.css
Full javascript : http://gdata-samples.googlecode.com/svn/trunk/ytplayer/ChapterMarkerPlayer/chapter_marker_player.js
Can anyone please provide me some codes or samples similar to this. So, I can get some idea how to do this.. Thank you very much :)
The youtube api has this script
function getCurrentTime() {
ytplayer.getCurrentTime();
}
Where "ytplayer" is your targeted player.
I would say then you can use
setInterval(getCurrentTime(), 3000);
and check if it matches.
You would need to have var's set up with values to test against.
= to ? but < ??
After that the script can change the css of the div accordingly. onClick would need to have the same result.
New Codes:
function clearList() {
var list = document.getElementById("chapter-list");
var items = list.getElementsByTagName("li");
for (var i = 0; i < items.length; i++) {
items[i].removeAttribute("class");
}
}
function highlightChapter(player) {
setInterval(function() {
var status = player.getPlayerState();
if (status>0) {
var currentTime = player.getCurrentTime() ;
list = document.getElementById('chapter-list');
for (var i = 0; i < times.length; i++) {
var time = times[i];
var item = list.children[i];
if (currentTime>=time) {
clearList();
item.setAttribute('class', 'current');
}
}
}
}, 1000);
}
Edited Code:
function addChapterMarkers(containerElement, player) {
var ol = document.createElement('ol');
ol.setAttribute('class', 'chapter-list');
ol.setAttribute('id', 'chapter-list'); ////////////// HERE
ol.setAttribute('style', 'width: ' + width + 'px');
containerElement.appendChild(ol);
for (var i = 0; i < times.length; i++) {
var time = times[i];
var chapterTitle = params.chapters[time];
var li = document.createElement('li');
li.setAttribute('data-time', time);
li.textContent = formatTimestamp(time) + ': ' + chapterTitle;
li.onclick = function() {
// 'this' will refer to the element that was clicked.
player.seekTo(this.getAttribute('data-time'));
//my code
clearList(); //// ADDITIONAL CODE
this.setAttribute('class', 'current'); //// ADDITIONAL CODE
// end my code
};
ol.appendChild(li);
}
}
function insertPlayerAndAddChapterMarkers(params) {
var containerElement = document.getElementById(params.container);
if (!containerElement) {
throw 'The "container" parameter must be set to the id of a existing HTML element.';
}
var player = initializePlayer(containerElement, params);
addChapterMarkers(containerElement, player);
highlightChapter(player); ////// INSERT
}
Everyone is suggesting some framework, but I'd like to know how it can be done in native JavaScript. I've tried this code and some other things, no effect. Seems that I'm unaware of some basic underlying concept. Any help would be appreciated.
window.onload = function() {
var trCurrent
var main = document.getElementById('main');
var tr = main.getElementsByTagName('tr');
function hl() {
trCurrent.setAttribute('class', 'highlight');
};
for (var x = 0; x < tr.lenght; x++) {
trCurrent = tr[x];
trCurrent.addEventListener ('mousedown', hl, false);
}
};
You have to change trCurrent to this at your function h1, becayse trCurrent points to the last defined TR element (trCurrent = tr[x] for a high x).
Use .length instead of .lenght.
Final code:
window.onload = function() {
var main = document.getElementById('main');
var tr = main.getElementsByTagName('tr');
function hl() {
this.setAttribute('class', 'highlight');
};
for (var x = 0; x < tr.length; x++) {
tr[x].addEventListener ('mousedown', hl, false);
}
};
If you want to use an variable which is subject to change during a loop, it's required to wrap the body in an (anonymous) function:
window.onload = function() {
var main = document.getElementById('main');
var tr = main.getElementsByTagName('tr');
for (var x = 0; x < tr.length; x++) {
(function(trCurrent){ //Anonymous wrapper, first argument: `trCurrent`
function hl() {
trCurrent.setAttribute('class', 'highlight');
};
trCurrent.addEventListener ('mousedown', hl, false);
})(tr[x]); //Passing a reference to `tr[x]`
}
};
Here is the script I have:
And I'm trying to assign event to each element in an array.
window.onload = sliding;
function sliding() {
document.getElementById('tag1').onmouseover = slideout;
document.getElementById('tag1').onmouseout = slidein;
}
And I tried do using the code below but that didn't work. It would trigger all the function buy it self.
window.onload = sliding;
var tags = new Array('tag1','tag2','tag3','tag4','tag5','tag6','tag7','tag8');// List of headings
var pics = new Array('popout1','popout2','popout3','popout4','popout5','popout6','popout7','popout8');// list of images that slide out
function sliding() {
for (var i = 0; i < tags.length; ++i) {
document.getElementById('tag1').onmouseover = setslideout(tags[i],pics[i]);
document.getElementById('tag1').onmouseout= setslidein(tags[i],pics[i]);
}
}
Here is full code
window.onload = sliding;
var tags = new Array('tag1','tag2','tag3','tag4','tag5','tag6','tag7','tag8');// List of headings
var pics = new Array('popout1','popout2','popout3','popout4','popout5','popout6','popout7','popout8');// list of images that slide out
function sliding() {
/*for (var i = 0; i < tags.length; ++i) {
setslideout(tags[i],pics[i]);
}/*/
document.getElementById('tag1').onmouseover = slideout;
document.getElementById('tag1').onmouseout = slidein;
}/*
function setslideout(tagsid,picsid){
document.getElementById(tagsid).onmouseover = slideout(tagsid,picsid);
}*/
function slideout(){
//alert('over '+ lid);
if(currpos('popout1') < 200){
document.getElementById('popout1').style.left = currpos('popout1') + 10 + "px";
var timer = setTimeout(slideout,10)
}else{
clearTimeout(timer);
}
}
function slidein(){
//alert('over '+ lid);
if(currpos('popout1') > 0){
document.getElementById('popout1').style.left = currpos('popout1') - 20 + "px";
var timer2 = setTimeout(slidein,10)
}else{
clearTimeout(timer2);
}
}
function currpos(element){
return document.getElementById(element).offsetLeft;
}
Here what im trying to to http://signsourceak.com/index2.html (first link in the drop down works )
Here's a version of your code modified to use closures, hopefully this does the trick:
window.onload = sliding;
var tags = new Array('tag1','tag2','tag3','tag4','tag5','tag6','tag7','tag8');// List of headings
var pics = new Array('popout1','popout2','popout3','popout4','popout5','popout6','popout7','popout8');// list of images that slide out
function sliding() {
for (var i = 0; i < tags.length; ++i) {
document.getElementById(tags[i]).onmouseover = (function(j){
return function(){
setslideout(tags[j], pics[j]);
}
})(i);
document.getElementById(tags[i]).onmouseout = (function(j){
return function(){
setslidein(tags[j], pics[j]);
}
})(i);
}
}