I stumbled upon some strange behaviour of auto-magically parsed numbers in javascript.
I have some product objects to show in a tabs component (of jquery UI) and these objects are only temporary so I prepared for every one of them some unique ID. I generate them so they look like this: 540718791327b
The thing is my script which used them to identify on which tab I actually work at the moment stopped working at some point. I didn't know what happened until I did some debugging. I noticed that the uid I had in source like this: 5407153722e09 was being read by javascript as a number: 5407153722000000000. It seems javascript treated my number as a scientific notation.
Unfortunately I wasn't able to reproduce it with jsfiddle, but here it is so you get an idea what am I doing: http://jsfiddle.net/7a3952qt/
Generally at my PC the console.log(uid) returns 5407153722000000000 instead of 5407153722e09. (on my webpage, on jsfiddle it works fine)
Maybe someone has any idea what might be going on? What can be the cause of behaviour like this?
Related
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
Currently I am looking for efficient (means made by someone else) way to represent JS objects inside HTML page. Ideally I should provide arbitrary object and library should make dropdown or popup with all properties of that object that can be selected and viewed as well. Final goal is to make object representation as close to modern JS debugger interface as possible.
In case if I didn't get my point accross I want to find libarary that would allow to represent object on web page as on picture below.
So I would like to ask if any of you know a libarary that can help me to do this.
Update: I found that firebug-lite-debug.js has similar functionality but such approach requires unknown amount of work to extract code I need
Upadate: I ended up using json-formatter-js. It is able to render any js object and do it in lasy way so only expanded part of object is taken into account. Therefore gigantic things as window can be displayed.
It sounds like you just want a pre-made widget that will display an object as HTML?
I'd probably start with something like html-stringify
It spits out a mostly clean HTML string with basic formatting. You could use that directly in your page, or add some additional styles to help match the style of your page. You can try it out on RunKit to see if it'll meet your needs.
(RunKit is a nice way to try out packages like this, so you can see what the output looks like without having to install them.)
I'm relatively new to using Chrome developer tools/doing XPath searches/this kind of programming in general, so please excuse any incorrect terminology or vague-sounding descriptions. I think the screenshots below will demonstrate what I'm talking about more easily than I can describe with my limited vocabulary.
What I'm Looking For
When I started using developer tools to search XPaths, using the "$x(...)" function would return a section of the html, that I could then navigate within the console or with more specific searches to get a sense of the structure before I extracted text. My console is no longer returning the markup text in this form, but I found an example in another StackOverflow post that will suffice to show what kind of return I'm looking for:
What I would be looking for
I was able to navigate this HTML text within the console (highlighted section) to find the section I needed, before using a more specific XPath, extracting, etc.
What I'm Seeing Now
What I'm now getting instead is an array or nested set of arrays. I think that these are jQuery objects being returned (could be way off here). See below:
What I'm seeing now
I'm sure that in many cases, navigating the elements in this array could actually be easier than working through the HTML and, as someone with very little exposure to web development, I'm sure that there's something I'm missing here. As someone working on a scraping project just looking to find specific elements or text on the page. This is much more difficult to work with.
As a made up example, in the past, if I were trying to pull the names of different kinds of fruit off of a page and I typed into the console...
$x('//*[#class="fruit"]/h1')
...the console would have spit out something like:
[<h1>Peach</h1>, <h1>Strawberry</h1>, <h1>Watermelon</h1>, <h1>Apple</h1>, <h1>Orange</h1>]
And then, had I followed that up with...
$x('//*[#class="fruit"]/h1.text()')
...the console would have spit out:
["Peach", "Strawberry", "Watermelon", "Apple", "Orange"]
Now, if I run a search like this, I'll get a result that will (not literally, but in this form) look something like this:
Array[2]0: form#aspnetForm0: input#__LASTFOCUS1: input#__EVENTTARGET2: input#__EVENTARGUMENT3: input#EktronClientManager4: input#__VIEWSTATE5: input#__VIEWSTATEGENERATOR6: input#__EVENTVALIDATION7: input#ctl00_Header_searchTextBox.searchterm8: input#ctl00_Header_searchButton.searchbtn9: fieldset10: input#ctl00_contentPlaceHolder_login_emailTextBox.max-width11: input#ctl00_contentPlaceHolder_login_passwordTextBox.max-width12: input#ctl00_contentPlaceHolder_login_rememberMeCheckBox13: input#ctl00_contentPlaceHolder_login_signInButton.button.green_events: etc, etc...
For my purposes, that array of strings is much easier to work with, because I can confirm exactly what I'm getting from that XPath search and what I'm going to have to work with once I get the element off the site.
I'm sorry that this post is probably really frustrating to an experienced web programmer, because I'm missing both the larger picture and a lot of the vocabulary. Could someone please explain to me 1. what I going on? Why am I getting these arrays full of data when I was getting the HTML text before and 2. how to revert to getting the HTML text returned when I do this kind of search in the JavaScript console?
Thank you!
There is no difference between the "what I would be looking for" and "what I'm seeing now" screenshots. When you click on the little triangle to the left of "what I would be looking for", you can see that it becomes equivalent to the "what I'm seeing now" format.
For example, opening up DevTools on this very Stack Overflow page, and searching for <h2> elements:
When you click on the little triangle to the left of the result you get:
The $x() function returns a JavaScript array (not jQuery) of DOM nodes that match your XPath query. If there's multiple nodes that match your query, then the result will be an array of multiple nodes.
You can iterate through the results by assigning the results to an array, and then looping through them, like in the screenshot below. I think this is the kind of functionality that you're looking for.
Moving from InDesign to Acrobat now, I need to automate a very simple task. I'll eventually use BridgeTalk to have an InDesign script call Acrobat X and have it do a couple of simple things. To this end I've been reading up on how to script Acrobat. Unfortunately, it does not seem anywhere as simple as scripting InDesign or Illustrator.
For one thing, the ExtendScript Toolkit is now useless since Acrobat has a built-in "Javascript Console". This would be perfectly fine, except that my console seems to be completely broken. Once I launched it (and it was hellacious just trying to figure that out), I type in a simple 3 + 4 in the console and press Command+Enter, as noted in Thom Parker's guide on AcrobatUsers. (I don't have a fancy Mac extended keyboard with a numeric keypad, so I have to use Command+Enter.)
Nothing happens.
I've tried other things, such as selecting the code first, pressing Control+Enter instead, using a different line of code such as console.println("Hello.");, etc. Nothing I do seems to work. What am I doing wrong?
Finally got my question answered over on Adobe's forums. I thought I had tried everything, but it turns out that I had not even tried a simple Shift + Enter. Hard to believe, since I thought I'd tried every possible key combination already, but I cannot deny the facts. Since I only had the small Apple keyboard without the numeric keypad, I suppose this is the only way to get Enter instead of Return from that key. At any rate, the answer is now known!
It seems to be command-return on MacOS 10.13.6 But thanks for the hint above.
I'm sure I'm overlooking something here but, I have code like so (its more complicated but I think I can safely break it down to these components):
setTimeout(window.location.assign(page),400);
page is a url like 'http://www.this.com'
The problem is that the newly assigned page has RANDOM numbers appended to it. To clarify, instead of being redirected from here.com to here.com/there, it goes here.com to here.com/-54
It looks like I'm returning a value somewhere but I'm not sure where the misuse is as I'm unfamiliar with this function. Anyone see where things have gone awry?
Thanks!
I tried this out in Firefox and I'm not getting any problems (well, other than what #Gerben mentioned in comments)
setTimeout(window.location.assign("http://google.com"),400);
So, I have some questions for you:
What browser are you using?
Have you tried this and experienced the same problem in other
browsers?
Have you tried checking the string in the page variable? alert(page);
FYI #Gerben means to rewrite your code like this if you want the timeout to actually work
setTimeout(function() {window.location.assign(page);},400);