Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
I have a javascript code for our online chat that we use in our application. But I need this code to not appear on a specific page, eg domain/X1XY.
Can you advise me how I can write this in the main code that is called on each of our pages?
<!-- Smartsupp Live Chat script -->
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = '123456789';
window.smartsupp||(function(d) {
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
</script>
If the URL of the page is unique, then you can use it to conditionally run the JavaScript using the document object's URL property:
<script type="text/javascript">
if (document.URL !== 'https://<your URL here>') {
var _smartsupp = _smartsupp || {};
_smartsupp.key = '123456789';
window.smartsupp ||
(function (d) {
var s,
c,
o = (smartsupp = function () {
o._.push(arguments);
});
o._ = [];
s = d.getElementsByTagName('script')[0];
c = d.createElement('script');
c.type = 'text/javascript';
c.charset = 'utf-8';
c.async = true;
c.src = 'https://www.smartsuppchat.com/loader.js?';
s.parentNode.insertBefore(c, s);
})(document);
}
</script>
Hope this helps.
if (window.location.pathname !== '/X1XY') { // your code here }
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
I'm trying to replace all HREF with domain1.com with the URL described in his title (if it has a title).
var els = document.getElementsByTagName('a'),
for (els in url) {
if (url.includes(domain1)); {
var titulo = url.attr('title');
var enlace = url.attr('href');
url.replace(enlace, titulo);
}
}
<p style="margin:40px;" line-height:2px;=""><img src="https://www.domain1.com/738956_1.jpg" data-width="1070" data-height="1387" data-image="738956-sanKH" alt="738956-sanKH.jpg">XS texto<br>
<img src="https://www.domain1.com/738956_1.jpg" data-width="1077" data-height="1693" data-image="738956-iMkWh" alt="738956-iMkWh.jpg">S texto</p>
I'm a beginner in javascript. Sure have a lot of format mistakes. Thanks in advance
Here is a tested JavaScript code, replace the for..of with for..in if you want to support Internet Explorer browser.
var domain1 = 'domain1.com';
var els = document.getElementsByTagName('a');
for (var url of els) {
var title = url.getAttribute('title');
if (title && url.getAttribute('href').search(domain1) !== -1) {
url.setAttribute('href', title);
}
}
If your DOM is having all the links after document load, then you can do this:
window.onload = bindEvents;
function bindEvents() {
// replace href with title
bindAnchorTitleAsHref();
}
function bindAnchorTitleAsHref() {
const els = document.getElementsByTagName('a');
for (let i = 0; i < els.length; i += 1) {
const title = els[i].getAttribute('title');
const href = els[i].getAttribute('href')
els[i].setAttribute('href', title);
console.log('New Href set :', els[i].getAttribute('href'), 'instead of', href);
}
}
<a
href="https://www.domian1.com/plants"
title="https://www.newdomain.com/test1"
target="_blank"
rel="nofollow noopener"
>
texto
</a>
If you just want to update the domain of the link, then you can use the URL class:
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('a[title]').forEach(el => {
const href = new URL(el.href);
if ((/[\^\.]domain1.com$/i).test(href.host)) {
const title = new URL(el.title);
href.host = title.host;
el.href = href.toString();
}
});
});
<p style="margin:40px;" line-height:2px;=""><img src="https://www.domain1.com/738956_1.jpg" data-width="1070" data-height="1387" data-image="738956-sanKH" alt="738956-sanKH.jpg">XS texto<br>
<img src="https://www.domain1.com/738956_1.jpg" data-width="1077" data-height="1693" data-image="738956-iMkWh" alt="738956-iMkWh.jpg">S texto</p>
I'm trying to integrate Disqus on my test Magento website. I'm using NeoTheme Blog Extension however I disabled the built in comment section and change it to disqus.
The problem was the canonical url. I have a main category http://?????.com/news-and-media/ that has a sub category /blog and /news and others. The blog page can be access as http://????/.com/news-and-media/blog-content and http://????/.com/news-and-media/blog/blog-content, both display the same content. I tried to comment on each url however the comment is missing from the other page and vice versa.
This is my progress so far.
My phtml
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = 'http://?????.com/news-and-media/';
this.page.identifier = 'blog';
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://????-com.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
My local.xml
<neotheme_blog_post_index>
<reference name="disquscomment">
<block type="core/template" name="dcomment" template="disqus-comments.phtml" />
</reference>
</neotheme_blog_post_index>
Do you have solution for this canonical? I can't seemed to undesrtand the documentation and example.
https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
How to make Disqus to work with url routing?
You have to fetch the rel canonical value using javascript and use it as your page identifier. I'm not sure if this works.
var canonical = "";
var links = document.getElementsByTagName("link");
for (var i = 0; i < links.length; i ++) {
if (links[i].getAttribute("rel") === "canonical") {
canonical = links[i].getAttribute("href")
}
}
var disqus_config = function () {
this.page.url = '';
this.page.identifier = canonical;
};
(function() { // DON'T EDIT BELOW THIS LINE
Check this link for reference. http://javascript.qahowto.com/Obtaining-canonical-url-using-JavaScript-javascript-url-5b420a
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Is there any function that i can use?
Or i need to create one? Or can i use push? It is modified script from this page:
http://code-maven.com/automatic-counter-using-angularjs
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
<script>
angular.module('CounterApp', [])
.controller('CounterController', function($scope, $timeout) {
var timer;
$scope.stored = [];
$scope.counter= 0;
$scope.stopCounter = function() {
$timeout.cancel(timer);
timer = null;
};
$scope.startCounter = function() {
if (timer === null) {
updateCounter();
}
$scope.stored.push(counter);
};
$scope.pushedVariable = function() {
$scope.stored.push(counter);
};
var updateCounter = function() {
$scope.counter++;
timer = $timeout(updateCounter, 1000);
};
$timeout.cancel(timer);
timer = null;
});
</script>
<div ng-app="CounterApp">
<div ng-controller="CounterController">
<button ng-click="stopCounter()">Stop</button>
<button ng-click="startCounter()">Start</button>
<button ng-click="pushedVariable()">Push</button>
{{counter}}
<p>Stored Variable 1: {{stored[0]}}</p>
<p>Stored Variable 2: {{stored[1]}}</p>
</div>
</div>
You just need to use $scope.stored.push($scope.counter); in your function instead of your current $scope.stored.push(counter); which is an undefined variable.
function(obj) {
var str = [];
for(var val in obj)
str.push(encodeURIComponent(val) + "=" + encodeURIComponent(obj[val]));
}
Where "obj" is your object.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to make this script auto change between the four after 30 seconds, I am not to good at jquery but I wanted to give it a try. This is all on a .php page I am using to bring up the javascript from my other folders.
<div id="subnavi">
<div id="subnavi-user">
<div style="margin-top:7px"><b>Fact:</b> <script language="JavaScript">
var r_text = new Array ();
r_text[0] = "{hotelName} was founded in 2011 by Kyle";
r_text[1] = "{hotelName} strives to remain as professional as possible.";
r_text[2] = "{hotelName} will only keep on growing if you vote daily!";
r_text[3] = "Purchasing VIP in the forums helps with the monthly server costs.";
r_text[4] = "{hotelName} Is a new and developing RP!";
window.setInterval(function(){
var i = Math.floor(4 * Math.random())
document.write(r_text[i]);
var random = r_text[1];
}, 5000);
</script>
</div>
</div>
<div id="subnavi-search">
<div id="subnavi-search-upper">
<ul id="subnavi-search-links">
<li>Sign Out</li>
I am not sure if this is what you are looking for but here it is:
This script will run every time you reload the page. IF you need it to work in a different way just update your question and i will update my script.
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var r_text = new Array();
r_text[0] = "Hello";
r_text[1] = "Test";
r_text[2] = "We are the lions";
r_text[3] = "Fight";
r_text[4] = "Switch!";
window.setInterval(function(){
var i = Math.floor(5 * Math.random())
var random = r_text[i];
$('#r_text').html(random);
}, 5000); // you can change the interval here
The HTML part
<div id="r_text"></div>
Check this out here
Update
Change your Math.floor to count to 5 because your array has 5 elements in it not 4
Update 2 Your file should look like something like this
<!Document html>
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var r_text = new Array();
r_text[0] = "Hello";
r_text[1] = "Test";
r_text[2] = "We are the lions";
r_text[3] = "Fight";
r_text[4] = "Switch!";
window.setInterval(function(){
var i = Math.floor(5 * Math.random())
var random = r_text[i];
$('#r_text').html(random);
}, 5000); // you can change the interval here
</script>
</head>
<body>
//Add your html/php code here and pick a place where to show the response of your function. Something like <div id="r_text"></div>
</body>
</html>
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
jQuery Pagination Plugin
I am trying to add a pagination of some kind on my website: www.metallica-gr.net and although I tried some of the jquery ones I had a hard time understanding how I would implement it on my site.
Here's how my site is built, and how articles are displayed. Is it possible to make pagination for this?
http://imageshack.us/a/img268/249/paginationq.jpg
If you only have a bunch of static files then you would probably be better off just creating the links yourself. I think these types of things are more useful with dynamic websites. Something to this effect.
<html>
<head>
<script type="text/javascript">
var baseUrl="www.mysite.com?page=";
var forwardLinkId ="fwdLink";
var backwardLinkId = "bwdLink";
function SetForwardUrl(forwardLink)
{
var page = gup(pageNumber)
var fwd = document.getElementById(forwardLink);
var fwd.href = baseUrl + (page.ToNumber() + 1);
}
function SetBackworddUrl(backwordLink)
{
var page = gup(pageNumber)
var bwd = document.getElementById(backwordLink);
var bwd .href = baseUrl + (page.ToNumber() - 1);
}
function gup(name)
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
document.onload = function() {
SetForwardUrl(fwdLink);
SetBackwardUrl(bwdLink);
}
</script>
</head>
<body>
<a id="fwdLink" /> <a id="bwdLink" />
</body>
</html>