find javascript changing HTML - javascript

First off, I'm not a developer, but a site owner running wordpress. my site has some Amazon affiliate URLS. What is happening is some rogue javascript is running and changing the referral ID's of the HTML code only from a google search specifically (If I load a page directly the HTML doesn't change). Basically I'm trying to figure out how to locate it, I figure that by looking at the html section I can trace what javascript is changing the HTML? With that information maybe I can help find it or pass that on to the hosting company to remove the file.
For example:
in the website shows : https://amazon.com/49684095/?tag=properamazontag
the javascript runs and changes to: https://amazon.com/49684095/?tag=douchebagscammercode
I hope it makes sense.
I have disabled javascript in the browser and confirm that the HTML code doesn't change, so I know it's a javascript issue.

For anyone looking at this with the same issue, what I did was follow this thread Find javascript that is changing DOM element. I went through all the JS changes looking for odd code not associated with a plugin file or theme.
once I found the code, I used a plugin called string locator and searched "everything under WP-content" for the first part of the bad code. From the plugin shows the location of the code (a JS file was added to the theme template) and I then used the same technique to search for the names JS file (in this case called theme.js) and found a php line in the functions.php file that had to be deleted along with the file.

Related

adding javascript to wordpress pages

I got thrown at a project that is using Wordpress for generating websites. Once done, the team takes a copy of the generated static html code and puts it on some webhosting platform as a standalone website.
I am now asked to add some function adding dynamic behavior to a page by calling a webservice and add some of its data to that page.
I tried adding javascript using the custom html widget of the Gutenberg editor but it does not work well. I could make it work for simple things but firing a request did not work and it is hard to debug.
Wondering, is a plugin the right way to go for or are there better ideas?
I assume it needs to be some some php code adding javascript contained in html I guess?

How to debug js loaded in ajax request in Chrome DevTools

Actually I am a big fan of Google Chrome DevTools but it is very vast area for learning. I don't know much about it. I know how to out debug point, searching (Ctrl+Alt+F) and debugging, etc. basic things.
But in one of my project (its in asp.net MVC), it is requesting different views in Ajax request and in that views there are some js loading. I want to debug them but I am not able to. Actually I don't know where can I see them - especially the JS which is load after ajax call (its not inline javascript but a separate js files).
A workaround I found is - if I put 1 "debugger;" in that js file then it opens with some VM3012 or similar name with different numbers. Then only I can see the files. But I can not put debugger when I publish the code.
Any body knows then please help.
Thanks a lot for reading.
EDIT
as per first answer, I have tried but I can see that option "Open in Source panel" for normal JS file. But in my case my request is passing some query string to the js file like assets/components/utility/mycustom.js?_=1528282662460 and I am not able to see that option for such request. This help is appreciated but need more.
I know it's been 3 years but...
You can name the piece of javascript code inside the dynamic loaded file by adding the following above the code:
//# sourceURL=my-file-name.js
By doing it, that piece of javascript will be available in the file tree of the source panel and can also be found by the DevTools' CTRL+P shortcut.
Go to the network tab of the dev tools. You can filter by js files to help you find the file you need. Right click on the file you want and select Open in sources panel. You should now be able to put the breakpoint where you like as you are used to.

How to make a Topic editor

I was searching until now and I've got nothing , I want to make a topic Editor in my Laravel project (where the user can write a Rich Text) . I found many JavaScript plugins where the user can create his document and the plugin will create the HTML code in the background
But the problem is that the user can get into the HTML code and change it to add scripts or anything (XSS) so I wanted to know what programmers usually do in such a situation :
do they filter the requested HTML on the server side (If so Help me with a source or a function)
will they create a normal text like StackOverFlow then they change the text to HTML on the server EXP:[img:link]=><img src="link"/>
So this is my problem and I don't know what to write exactly in google so please help with any idea
You have to check the data server side anyway, so do a HTML processing there and allow only specific tags.

How to include an external PHP file into a Joomla article?

So basically, I have a single article that I would like to load a PHP file into. This PHP file has a bunch of PHP and Javascript, along with HTML.
I need to include this full PHP file into my article since it contains an application form that I need on my website.
I have tried the following:
Using an extension to allow PHP and Javascript code within an article. Although, this is extremely time consuming since all PHP and Javascript must be wrapped in some special tags for the extension to recognise it, therefore this would take me days.
I tried using the extension and then trying <?php include "form.php"; ?> within the special tags, although this returned a major error since I believe it is because the PHP code is not within the tags itself.
Does anyone have any suggestions to how I can accomplish this?
Try this ,
Create a module that have your forms. For module development tutorial
And create an article and set the module inside that like.
{loadposition contact_form_pos}
Inside your article just mention the module position like above
for more
Using extensions is the only way to do that.
If you don't want to use a plugin that allows PHP into articles, you would have to write your own custom component to show that php page in your own menu item, out of an article.
It's a little hard to answer when you haven't said if you want to just do this one time in one specific article or you want to be able to put it into any article.

Find and track javascript code that modified the DOM

There is a javascript event that is modifying a search box but since I was not the original developer, I have no clue where it was written. I know it's Javascript because when I disabled Javascript in the browser it stopped working. But this is the Drupal CMS with tonnes of .js files and this person followed none of the standard places for putting .js files. How do I track down where the snippet of code that is causing the trouble is located?
The Chrome Inspector tool can do that.
An answer you're going to want to read is here: https://stackoverflow.com/a/7054733 .

Categories

Resources