Script In Formula Text Search Result - javascript

I have a search result column where I'm using the record ID to pass parameters as a link to a non-netsuite external site I own that is designed for a specific non-NetSuite task.
The link is working great and the formula looks something like this:
'Use Tool'
However, I'd like to add some script to it by using onClick, and each time I've tried this either I get back invalid expression or the script seems to get stripped out of the link.
I've added what should just be a simple alert window with the record id as a test like this:
'Use Tool'
but using the dev tools to inspect this the search result shows up like this:
Use MT Tool With Tracking
I'd like to track something simple like which user clicked the link and what day it was, but I'm starting to think that this might not be possible.
Has anyone ever tried doing something like this before?
Is there a better way to do this?
Thanks in advance for any help.

It may be a rudimentary attempt on NetSuite's part to prevent XSS attempts, but if you don't need to support Internet Explorer you can get around it using the template literal syntax.
'Use Tool'

I still think the escaped double quote is a problem ☺, but I was able to duplicate your issue in preview mode (I think it's a result of NetSuite's whence parameter). Run or Save and Run does not encounter the issue. See screenshots of Search Formula Text fields below and corresponding elements when run.
Lazy Loader
Result
Element

Related

Button as a fake link for a Google Analytics funnel

I'm trying to set up a funnel that has a final step of clicking on a button and downloading a document. Since I can't track the button, I was hoping to set up a fake link that doesn't redirect the user anywhere but allows Google Analytics to see how many people clicked on the button.
What I have is this Javascript piece of code but when it gives me an error:
<a href=”/goal/example” onclick=”javascript:pageTracker._trackPageview (‘example’);”target=”blank”>
Or, if this doesn't work at all, is there any other way to add a button to my funnel?
Thanks!
To piggy-back on #nyuen's answer, (though without your error message it's hard to know what's wrong), it looks like your link could be improved as well. First, since it sounds like you'd rather it not link anywhere, I'd set the href to your code rather than the onclick. And second, if you don't want it leading anywhere a target="blank" is going to be annoying. (Also I assume your <a> is closed eventually). Try:
[...]
There's a couple things wrong with the code looks like. Try this:
onclick="_gaq.push(['_trackPageview', 'example'])"
The javascript part is optional, and also the quotes need to be straight quotes, not the 'smart' quotes.

How can I find what changes an element?

I have some rather lengthy HTML and related styles and javascript. I am trying to find something within them that changes the text of a specific element. It changes this...
<span class="panel-title"> I'm a Panel with All Options</span>
... to this ...
<span class="panel-title">Best Panel Ever</span>
It seems crazy, but I tried searching every single file (1704 of them) for the text "Best Panel" and Visual Studio found nothing.
So... I am hoping that a debugger in Chrome or IE can point me to script is changing this text but I'm not familiar enough with those debugging tools to perform a task like this... or if it's even possible.
Edit for Clarification
Just to be clear... this is straight HTML, CSS, and Javascript. There is nothing like ASP or PHP involved. The HTML file in question has the first text, but the rendered HTML file has the second text.
You can using the Elements tab in Chrome find a specific item in the code (CTRL + F). This screenshot might help: http://gyazo.com/72f2f8a819bf5bfad17a210a53427f2d - It may or may not help.
Edit 1
Are you sure you looked through every single file? Maybe that Best Panel Ever is coming from a database entry which has been attacked or it may just be an attack not through a database. Have you considered that to be an option?
Edit 2
As suggested in the chat you should probably search for occurences where the span is being changed rather than looking for a specific value as it may be stored in a variable which isn't showing the text.
Edit 3
After finding out it was something to do with LS (local storage):
I think it should be broke down in to steps, first ensure that the value in question is in LS that way you can narrow down your search to localStorage.getItem("yourKeyWhichHoldTheText") and you'd have a rough idea what you are actually looking for.
The latest versions of FireFox have a javascript event inspector. Perhaps you could inspect that element for any possible js functions that could be updating it?
Here's a resource
and another

Disable URL Shortening/ Formatting in Chrome's Console

I'm converting pages from an old format to new via Snippets. All was right in the world, up until I noticed Chrome's console "shortening" URL's so they would display better.
var url = "http://www.somewebsite.com/this/is/a/really/really/really/really/long/ass/url/that/will/be/cutoff/later/on/just/wait/wait/for/it/wait/for/it/there/here/are/some/query/strings?awwww=snap&this=is&really=happening"
console.log(url);
// Spits out
// "http://www.somewebsite.com/this/is/a/really/really/really/really/long/ass/u…r/it/there/here/are/some/query/strings?awwww=snap&this=is&really=happening"
These aren't the actual URL's, but you get the idea. Is there a way of removing formatting from Google Chrome's console area? This snag pretty much ruined all my plans, hoping to not have to use a headless browser just to get raw text output. :-\
One workaround I found wasn't to log the actual values I was wanting. Instead I set it to a window variable and use copy(window.varToCopy)
copy() is a native Chrome function you can use in the console to copy the data to your clipboard. Luckily it seems that it doesn't format anything you pass into it, so I can then get the actual URL rather than the broken one.
This is only a workaround, hopefully someone knows how to remove console formatting!
My workaround is to use console.dir(url);. It isn't designed for this purpose, but it definitely does the trick:
You can't really open the hierarchical listing, but you don't need to anyway.
I ran into this issue when I had a long array of long urls. Nothing of the above helped.
The solution I finally came up with is:
console.dir(JSON.stringify(urls))
When a URL is displayed in the Chrome Javascript console, there are some context menu (i.e. right-click menu) options to interact with that url. If all you want is to copy and paste the full text of the URL to another location for viewing, you can right-click on the URL in the console and select "Copy Link Address". Then, just paste anywhere - even back into the Javascript console, if you want! - and the full, unshortened URL is there for your viewing enjoyment.
While this doesn't disable Chrome's URL-shortening behavior, it is a more comfortable workaround to me than inserting Chrome-specific Javascript into my code.
I just had the same problem. I ended up using this little workaround, making the url a non-url by removing leading http/https:
console.log(url.replace(/^https?:\/\//,""));

How to live-style an user input using javascript/jquery

im searching for a libary or suggestions for making a real time styler in javascript/jquery. The idea is that my users have a html text input, i need to detect in real time some patterns and apply an style to it, for example is the user writes #some_text all after the # should be considered like a tag a have to be bold like #some_text.
Im very new at javascript so i have no idea of where to begin, i did some research but i didn't find any already made libary. Thanks for any help and suggestions!
What about something like jQuery Tagit?
You could initialize it like this:
<script>
$(function() {
var availableTags = [
"#some_text1",
"#some_text2",
"#some_text3"
];
$('#tags').tagit({tagSource: availableTags});
});
</script>
<ul id="tags"></ul>
Something like that is used right here, on this website. Whenever you write a question or an answer in the editor, you get a live update in the area below. When you apply formatting it's updated in real-time in the preview area.
This uses a standard mark-up syntax called Markdown. What's good about that is that there are many tools that support Markdown, so you can find integrations for jQuery and even offline editors (Windows and Mac).
Check this question and its answers for some editors that do this.
Also check out the stand-alone version of the Stack Overflow editor.
maybe this helps you a little bit to understand what you have to do:
http://jsfiddle.net/EeGxs/3/
All I did is add an event listener to 'keydown' which means a key is pressed, and then you just have a look if there is a '#' in the line and if you add it to the p -tag which is bold.
Its only a demonstration.

Python/Django : auto-URL finder + highlighter in Text

I created my first web app using Python, Django, Bootstrap and google-app-engine
The requirement I have is when people suggest external links, The program should be able to find and highlight as clickable URL in the text.
For example, when we give http://www.google.com in stackoverflow, it converted it as hyperlink
I have no idea how to achieve this, any help is greatly appreciated
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#urlize
Look into the python re module.
For example, taking John Gruber's URL regex pattern and matching it against his data set you could do something like...
giant_regex = r'''(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))'''
output_with_links = re.sub(giant_regex, r'\1', source_html)
Unfortunately this will capture actual links as well that don't need converting, but now your problem is finding the correct regex (which I'm sure has been documented online if you look). The python and django part is done.
This is not a full answer, but will get you started: to do what you want in Django, you will need to (1) take the input text that the user submits, (2) parse it for url patterns, and (3) return the html with a hyperlink to display in the View.
I don't know if there is a canonical regex for this purpose, but some that seem to work well are here and in this answer.
In SO, as you notice, the parsed text is first shown in a separate
display box and, once you hit "submit" is re-rendered. You can choose many ways to render the text (e.g. to parse the text on the client side with Javascript). However, for the first stage you should probably just create a "results" page with each url replaced with a hyperlink (<a href='url'>url</a>) to that url.

Categories