How to split url use javascript ?
The split() adjustment is acclimated to breach a cord into an arrangement of substrings, and allotment the new array. Tip: If an abandoned cord ("") is acclimated as the separator, the cord is breach amid anniversary character. Note: The split() adjustment does not change the aboriginal string.
Syntax
string.split(separator, limit)
Parameter Values
Separator: Optional. Specifies the character, or the regular expression, to apply for breaking the string. If canceled, the whole string will be returned (an array with only one item).
Limit: Optional. An integer that defines the number of splits, items after the split limit will not be included in the array.
Example 1
Omit the separator parameter:
var str = "How are you doing today?";
var res = str.split();
var res = str.split();
Example 2
$(document).ready(function() {
setTimeout(function() {
var url=window.parent.location.href;
var split=url.split("/");
var furl=split[0]+"//"+split[1]+split[2]+"/"+split[3];
$("#website_url").val(furl);
var url_string = new URL(url);
var keyword=url_string.searchParams.get("keyword");
if(keyword !=''){
$("#keyword").val(keyword);
}
var campaign=url_string.searchParams.get("campaign");
$("#campaign").val(campaign);
$("#medium").val(parent.document.referrer);
}, 5000);

No comments