Por qué no carga mis eventos de un archivo externo en JavaScript

Encontré una pregunta en ingles acerca de un problema de métodos pero ninguno en español y referente al titulo que menciono. Espero que resuelvan algunas dudas. Este es un archivo app.js externo ubicado entre los<head><script src="app.js"></scritp></head> que lo único que hace es pintar un “Hola Mundo” al index.html principal por medio de una acción del click.

document.getElementById("boton").addEventListener("click", function(){ document.getElementById("text").innerHTML = "Hello World";});

Al momento de cargar(F5) la pagina se observa un error en consola de Chrome:

Uncaught TypeError: Cannot read property ‘addEventListener’ of null

y algo parecido en Firefox:

TypeError: document.getElementById(…) is null

SharePoint 2013 using Javascript to create a picture library carousel

I am trying to extend the out of the box Picture Library Slideshow Web Part , to be able to click an image and be redirected to a new link. Each image has its own link. i created a new field in the web part and use REST api to reference it to get the id’s and url. but i cant change the link to use a new one.

Retrieving Lookup Values, Javascript SharePoint 2013, Not Working

I’ve seen a lot of info on the above question but none of it has answered what I’m looking for, so far. I’m trying to retrieve list items that have a great number of lookup fields. I’ve had success getting to some of the lookup values but not others and I can’t figure out why. Also, it would appear that ‘null’ items are not accepted in the returned data? If the lookup field does not contain a value, it throws an error? Below is my code.

The other issue (the big issue mentioned in my title) is that lookup values where I’m trying to pull in something, other than ID or Title, throws an error: reference not found or initialized. In this instance my lookup field is referencing a calc column returned as a single line of text (Course1Date). So my lookup field is Course1Date/DateRange, where DateRange represents the fieldname of the calc column. Error: “The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.” I have posted this same question on stackoverflow in hopes of spreading the question. Apologies in advance if I’m not supposed to do that.

function getLookupValues(){ var clientContext = SP.ClientContext.get_current(); var list = clientContext.get_web().get_lists().getByTitle('Lookup'); var caml = new SP.CamlQuery(); caml.set_viewXml('<View><Query><Where><Geq>' +              '<FieldRef Name=\'ID\'/><Value Type=\'Number\'>82</Value>' +              '</Geq></Where></Query><RowLimit>10</RowLimit></View>');   var returnedItems = list.getItems(caml); clientContext.load(returnedItems); clientContext.executeQueryAsync(success, failure); } function success(){ var listiteminfo=''; var enumerator = returnedItems.getEnumerator(); while(enumerator.moveNext()) {   var listItem = enumerator.get_current();   if(listItem.get_item('Course1')) {     var course1 = listItem.get_item('Course1').get_lookupValue();   }   if(listItem.get_item('Course2')) {     var course2 = listItem.get_item('Course2').get_lookupValue();   }   if(listItem.get_item('Course1Date')) {     var course1Date = listItem.get_item('Course1Date').get_lookupValue();   } //throws error for this lookup field   listiteminfo += '\nCourse1: '+course1+'\nCourse2: '+course2+'\nCourse1Date: '+course1Date;  } alert(listiteminfo);         } function failure(){ alert("Failed"); } 

change date in infopath form via javascript

I have a sharepoint 2019 site. in this site i want change date value in date field that build with infopath.

I can do this with JavaScript and all thing apparently is Ok. but when press the save button nothing change, even when i type date manually. while when i pick date from own datePicker and press Save, all thing work correct.

please help me : how can change this?

// dtcontrolId is input date id that use datePicker        var newDate = pyear + "-" + pmonth + "-" + pday; $  ("#" + dtcontrolId).val(newDate);  // after it i call OnClilck event 

Javascript – Mostrar un div sólo en landscape

Tengo un problema con mi script.

Estoy mostrando un div oculto #alert cuando #total=0, y lo que estoy buscando es que #alert SÓLO se muestre cuando la pantalla está en landscape. (Ver CSS).

El problema es que aunque en el CSS hay un @media screen el script lo ignora y siempre me muestra el div #alert a cualquier resolución de pantalla y en cualquier orientación, y la verdad es que no sé solucionarlo correctamente.

¿Cuál es el fragmento del script que debería agregar para evaluar si la pantalla está sólo en horizontal y hasta 999px ántes de mostrar el div #alert para un #total=0 …?

Ver DEMO en línea ( JSFiddle ).

Gracias por adelantado.

$  (document).ready(function() {   function manageRegalo() {      var totalStorage = Number(localStorage.getItem("total"));     var total = parseFloat($  ("#total").val());      if (totalStorage != null && total === 0) {       total = totalStorage;     }      if (total > 99.99 && total < 299.99) {       console.log("PASS");       $  ('#regalo').show();       $  ('#alert').hide();        if (localStorage.getItem('suppress_gift_tooltip_1') == null) {         $  ('.tooltip').show();         window.setTimeout(function() {           $  ('.tooltip').fadeOut('slow');         }, 2000);          //--------------------          if (!$  ("#notify")[0].paused) { //play audio           $  ("#notify")[0].pause(); //play audio           $  ("#notify")[0].currentTime = 0; //play audio          } else { // play audio           setTimeout(function() { //play audio             $  ("#notify")[0].play(); //play audio           })         }; //play audio          //--------------------          localStorage.setItem('suppress_gift_tooltip_1', 'true')       }      } else if (!total) {       $  ('#regalo').hide();       $  ('#alert').show();     } else {       console.log("FAIL");       $  ('#alert').hide();       $  ('#regalo').hide();     }   }    $  (document).on('click', function(event) {     const target = event.target;     if (target.matches('.comp-clone') || target.matches('.bbp')) {       manageRegalo();        localStorage.setItem('total', Number($  ("#total").val()));     }   });   manageRegalo(); }); 


#alert, .tooltip {   display: none }  @media screen and (max-width:999px) and (orientation:landscape) {   #alert {     display: block; } 


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>  <div id="regalo">REGALO</div>  <div class="tooltip">Tooltip</div>  <div id="alert">ALERT</div>  <input type="text" id="total" value="0"> <button type="button" class="bbp">Enter</button> 

How can I render a RichImageField as a ‘s CSS background image (without JavaScript)?

I am creating Sharepoint page layouts using a text editor (company won’t allow me to install Sharepoint Designer). In one of my layouts, users can add an image using a RichImageField. My layout code looks like this:

<PublishingWebControls:RichImageField FieldName="PublishingPageImage" runat="server"/>

I would like this field to alter the background-image CSS property of a <div> rather than simply render as a standard HTML <img> tag. I know I can easily accomplish this with JavaScript, but I was wondering if there was a way of doing this at the page-layout template level?

In my ideal world it would be something like this:

<div id="hero" style="background-image:url('$ {RichImageField.src}')">My Hero Area</div>

So, to reiterate: Is it possible to render a RichImageField as a div’s CSS background image (without JavaScript)?

Suspected phishing attack – is this obfuscated JavaScript dangerous? [on hold]

I encountered an email from someone with an HTML attachment (the user is somewhat trusted). I by mistake clicked on the attachment in Gmail but immediately closed the new window. On viewing the source code it looks like there’s obfuscated JavaScript code, suggesting something malicious. However, I’m battling to decode it to discover what it’s trying to do. I tried using http://deobfuscatejavascript.com/ which has been somewhat helpful, but some parts I can’t decode. It looks to be trying to replicate Gmail and ask for a username/password, but presumably it would then try send it somewhere – although I can’t find or decode that part.

I’ve added a paste bin below with the file (it had lots of white space which I’ve since removed):


It seems to using something called HTML Guardian on parts to obfuscate it.

Any help would be appreciated to discover if it really is dangerous or not.