I have this code to include in my php website but I keep getting this error: We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
I have left trusted domains field empty in disqus dashboard to allow development on localhost.
The id is specific to each post.
<script type="text/javascript">
var disqus_config = function () {
var id = <?php echo $_GET['id']; ?>;
this.page.url = 'localhost/blog/viewimage.php?id='+id;
this.page.identifier = id;
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://ashexcreations.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
Related
I have had the website for 3 years. This website is created by HTML, CSS, and JavaScript. I have made it by myself and there is always a WhatsApp icon at the bottom of the right. But 6 months ago, it disappeared. I looked up my code and there are no changes. How can I make my WhatsApp ıcon visible again?
Here is my code:
<script type="text/javascript">
(function () {
var options = {
whatsapp: "+9000000000", // Contact Number
call_to_action: "Merhaba, Size nasıl yardımcı olabilirim?",
position: "right",
};
var proto = document.location.protocol, host = "whatshelp.io", url = proto + "//static." + host;
var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = url + '/widget-send-button/js/init.js';
s.onload = function () { WhWidgetSendButton.init(host, proto, options); };
var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
})();
//</script>
The domain whatshelp.io is currently timing out, which is probably why the buttons are not working.
Based on archive.org, it appears at some point the site started to redirect to bothelp.io. However, updating the script to https://static.bothelp.io/widget-send-button/js/init.js returns a 404.
After some googling, I landed on this page: https://apps.shopify.com/whatshelp-chat-button
The description noted the following:
The GetButton widget (former WhatsHelp widget) takes website visitor directly...
Again, updated the script to https://static.getbutton.io/widget/bundle.js and success!
I then updated the configuration script you provided to the following (formatted for legibility):
<script type="text/javascript">
(function () {
var options = {
whatsapp: "+9000000000", // Contact Number
call_to_action: "Merhaba, Size nasıl yardımcı olabilirim?",
position: "right",
};
var proto = document.location.protocol,
host = "getbutton.io",
url = proto + "//static." + host;
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = url + '/widget-send-button/js/init.js';
s.onload = function () { WhWidgetSendButton.init(host, proto, options); };
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
})();
</script>
And saw the following:
As I am somewhat of a beginner in PHP and JQuery / AJAX coding, I am having a great deal of difficulty trying to accomplish the following task.
I have a file named footer_data.php which contains the following code (this is the entire code contained within the file):
<?php
if ($setting['facebook_on'] == 1) {
if (isset($_GET['task']) && $_GET['task'] != 'facebook_register')
include 'includes/wss_facebook.php';
if ((isset($user['facebook']) && $user['facebook'] == 1) || ($user['login_status'] == 0)) {
?>
<div id="fb-root"></div>
<script type="text/javascript">
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
// Init the SDK upon load
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $setting['facebook_appid'];?>', // App ID
channelUrl : '//'+window.location.hostname+'/includes/facebook_channel.php', // Path to your Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
<?php if ($user['login_status'] == 0) { ?>
FB.Event.subscribe('auth.login', function() {
window.location = "<?php echo $setting['site_url'];?>/facebook_auth.php"
});
<?php } ?>
FB.Event.subscribe('auth.logout', function() {
window.location = "<?php echo $setting['site_url'];?>/login.php?action=logout"
});
<?php if ($user['login_status'] == 1) { ?>
FB.getLoginStatus(function(response) {
if (response.status == '1') {
window.location = "<?php echo $setting['site_url'];?>/login.php?action=logout";
}
});
<?php } ?>
}
</script>
<?php
}
}
?>
Currently, the above code which is contained within the file footer_data.php will be executed every time a visitor visits any web page on my website. In other words, the code is executed on page load.
What I am trying to do is get the entire code that is contained in the footer_data.php file to be executed only when a visitor clicks on a button.
I know that this could be accomplished using JQuery / AJAX, but I have no idea how to incorporate AJAX / JQuery within the above code that I have posted.
To any respondents, please if possible, could you post complete code and not just code snippets.
Any help will be greatly appreciated.
Thanks in advance.
If the id of your button is clickMe then, try this to only executate the file:
$('#clickMe').click(function(){
$.ajax({
method: 'get',
url: 'footer_data.php',
success: function(data) {
alert("code executed!");
}
});
});
and this to executate and load its content to a HTML element, i.e. a div:
$('#clickMe').click(function(){
$('#yourDiv').load('footer_data.php');
});
See: http://api.jquery.com/load/ for more details.
I want to set up a conversion metric to track when a user has been on a page longer than 30 seconds. I'm confused about Google Adwords. It's provided me with a piece of javascript code to inject into my body tag. Here's my problem. There is no obvious piece of code that I see that actually initiates the conversion. Look below:
<!-- Google Code for 30+ Seconds on site Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = "my id here";
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "the label";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
My plan is to set up a simple timeout delay in javascript and once those 30 seconds have past, then run the code above. But will that work? I don't see any line that shouts "Hey, this line of code communicates to the google server and initiates this conversion". What do I need to do get this to work? Thanks.
The problem is, this code doesn't really "run" anything, it just tells the browser to load a script.
To add some delay in that, you need to create the JS element and inject it later in your page.
You could try something like that:
<script type="text/javascript">
var google_conversion_id = "my id here";
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "the label";
var google_remarketing_only = false;
var head = document.getElementsByTagName('head').item(0);
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', '//www.googleadservices.com/pagead/conversion.js');
setTimeout(function() {
head.appendChild(script);
}, 30000);
</script>
Or you could just use the asynchronous version of this ;-)
This question already has answers here:
Dynamically load a JavaScript file
(30 answers)
Closed 8 years ago.
I have this code:
<script src="http://external/js/file/url.js">
</script>
I want to do something like this-
<script>
if(2>1){
//include http://external/js/file/url.js
}
</script>
Any idea?
This question has been asked before in Include a Javascript File in another Javascript File.
This peice of code may fit what you have been looking for
function include(filename)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
head.appendChild(script)
}
if that script does not work, i suggest you to look over and read the post above: Include a Javascript File in another Javascript File.
I hope this helps, it may not be the answer you had been looking for, but it may just help.
You simply load it asynchronously like
if(yourCondition==true){
var d = document,
h = d.getElementsByTagName('head')[0],
s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'http://external/js/file/url.js';
h.appendChild(s);
}
You could use something like:
<script type="text/javascript">
if (condition == true) {
document.getElementsByTagName("head")[0].innerHTML += ("<script src=\"http://external/js/file/url.js\" type=\"text/javascript\"></script>");
}
</script>
I'm using opencart 1.5.5.1.
On the products pages I've already successfully changed the "Review" tab with a discussion tool by Disqus! and it works great.
But my website is dual language italian/english and I would like the users to read the discussion in the language they've chosen.
So I've created two differents disqus id's (two independent discussion boards).
On my product.tpl I had to insert their javascript that comes with a variable like:
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'xxxxxxxxxx';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
I would like to make the variable disqus_shortname to depend on language code given on the session.
As long as I understand I can get it by php with
$this->session->data['language']
or
$this->language->get('code')
but here we are talking about js!
How can I tell this script the statement if?
I need something like
if $this->language->get('code') == 'it' { var disqus_shortname = 'xxxxxxxxxxitalian'; }
else { var disqus_shortname = 'xxxxxxxxxxenglish'; }
Check whether you register a disqus shortname for your website on Disqus.
disqus_shortname
Tells the Disqus service your forum's shortname, which is the unique
identifier for your website as registered on Disqus. If undefined, the
Disqus embed will not load.
To load different language on the page,use
var disqus_config = function () {
this.language = "ru";
};
code like:
<?php
$language = ( $this->language->get('code') == 'it' )? 'it' : 'en';
?>
<script>
var disqus_config = function () {
this.language = "<?php echo $language; ?>";
};
http://help.disqus.com/customer/portal/articles/466249-can-disqus-be-loaded-in-different-languages-per-page-
In Your controller You would have to propagate the language code to the template (edit catalog/controller/product/product.php file) - add this:
$this->data['language_code'] = $this->language->get('code');
Then edit the template file this way (catalog/view/theme/<YOUR_THEME>/template/product/product.tpl):
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'xxxxxxxxxx<?php echo $language_code; ?>'; // here the mojo is done...
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>