javascript window.open url + json var - javascript

What I am trying to accomplish is to open a url(base) with an added var at the end.
window.open(https://vipparcel.com/package/detailed/ + json.id[0])
This was written by someone else to just display an image but I need it to pop more detailed info.
I DO NOT know javascript so its like a child poking at a dead animal here.
I have exhausted my normal go to's and then some to find more info on this.
the url would look like https://vipparcel.com/package/detailed/000000 if the info passes correctly.
Anything pointing me in the right direction would be extremely helpful!
Thank you in advanced.

Try this :
var myurl = "https://vipparcel.com/package/detailed/" + json.id[0];
window.open(myurl);

What errors are you getting? Looks like you're just missing quotations. If that's not the case, is json an object with an array of ids? If instead it's an array of objects with an id property, the following should work:
window.open('https://vipparcel.com/package/detailed/' + json[0].id)

It should look like this:
window.open('https://vipparcel.com/package/detailed/' + json.id[0]);
it's looking for a string to open the website by. You weren't passing a string through to it.

Related

Website Console Javascript > getElementsByName> Need defaultValue attribute returned

I am trying to get a unique identifier out of a ServiceNow webpage source code. I have identified where it is and I was hoping someone could help me to return the value that I need.
Here is an image of the attribute I would like returned.... any help would be appreciated. I am not familiar with JS so please forgive me if my terminology is not correct.
Then end goal is to take a baseURL and then add this string as a parameter to get the RPA software I am using to navigate to this page.
baseURL + defaultValue
I have tried many different combinations of document.querySelector and document.querySelectorAll
I am unfamiliar with js syntax so this is an uphill battle for me.
If I get you right, this can help you finding what you need:
let myElement = document.getElementByName("sys_original.x_eyit2_dsr_dsr_task.dsr_case")
let myDesiredValue = myElement[0].defaultValue
console.log(myDesiredValue)
What you are looking for is probably a JSON Object. I said "probably", because we don't have more details about your question.

% symbols in strings passed from javascript to controllers in grails in strings turning them null

So, Ive done some digging and I cant find a reason for this, I've got some javascript for a simple search like so: -
function search(searchString, domain, destinationIdentifier) {
alert(searchString)
var uri = formUriWithDefaults([domain, "/search"], {searchString : searchString})
}
This looks like this because Im using the same search for multiple different pages. Ive then got a simple controller like so: -
def search(String searchString) {
println("received search " + searchString)
....do other stuff to blow your mind....
}
If I enter "elephant" or "hyperloop" or "random" etc and search then these are output as I'd expect in the controller with a line reading "received search elephant" etc. But the moment I try and make it "hyper%" etc it then just prints out 'received search null' instead... Does anyone know why adding a % into my search string makes it go blam?
Thanks for any help, much appreciated!
You might want to try the encodeAsRaw() but, this may open up a security hole in you application for cross-site scripting. It would look something like this:
{searchString : searchString.encodeAsRaw()})
A better option might be to change the wildcard identifier to be '*' and then do a replace in the controller on only that char.
Something like this:
searchString = searchString.replace("*","%")

How to Split many Strings with Jquery

Let's say I have a bunch of strings which I get from user input. Each strings starts with a new line like the following example:
gordon:davis
harley:vona
empir:domen
furno:shyko
I would like to write a function in jQuery which loads the user data from the form and splits each row's sting. However I would ONLY need the first part of the strings, like:
gordon
harley
empir
furno
Is there any simple solution for this?
I have found something called: $.each(split) but I didn't get it work.
I'm sorry I'm a really newbie in Jquery, I hope you guys can help me out! Thanks in advance!
Use String.prototype.split method.
"gordon:davis".split(":") will return ["gordon","davis"]
Based on this, using Array.prototype.map or a JQuery version :
var strings = ["gordon:davis", "harley:vona"];
var splitStrings = strings.map(function (string) {
return string.split(":")[0];
});

how do I convert a querystring into a json object in jquery

This seems like a no brainer but surely there is either an internal js method or a jquery one to take a string like:
intTime=1324443870&fltOriginalAmount=0.00&strOriginalCurrency=GBP
...then a lot more vals and turn it into a JSON object?
I had a dig around this site and google and surprisingly drew blanks...
Anyone got an easy way to do this?
jQuery BBQ does exactly this. See $.deparam, "The opposite of jQuery.param, pretty much."
> var obj = $.deparam('intTime=1324443870&fltOriginalAmount=0.00&strOriginalCurrency=GBP')
> JSON.stringify(obj)
'{"intTime":"1324443870","fltOriginalAmount":"0.00","strOriginalCurrency":"GBP"}'
i used this hack...
$.parseJSON('{"' + qs.replace(/&/g, '","').replace(/=/g, '":"') + '"}');
demo here http://jsbin.com/niqaw/

Getting part of referring url with jquery

I'm trying to set a cookie with a value that is made up of part of a referring url. The referring url looks something like:
http://webct.university.ac.uk/webct/urw/lc715920578061.tp721521425061/courseMenu.dowebct?
and I need to extract:
lc715920578061.tp721521425061
for reuse in another function.
Would this be regex? Could anyone help with the syntax?
Many thanks
Matthew
You can use replace with a regex and split like this:
var desired_part = document.referrer.replace(/^https?:\/\//gi, '').split('/')[3];

Categories

Resources