href link looking for url on local host - javascript

I am trying to make a dynamic link so that people using my web app can go to a web page that has additional information. The sites that the link goes to all have the same base url and are differentiated by a unique id at the end of the url (in this case an APN). When the page loads the link looks exactly as it should but when I click it goes to a file that doesn't exist on my desktop.
Here is my code:
var template = new InfoTemplate();
template.setTitle("<b>Parcel</b>");
template.setContent("<hr>Parcel No: <b>${APN}</b>" +
"<hr>Book No: <b>${BOOK}</b>" +
"<hr>Page No: <b>${PAGE}</b>" +
"<hr>Address: <b>${SitusAddress}</b>" +
"<hr>Appraised Value: <b>${Imps}</b> " +
"<hr>Year Built: <b>${YearBuilt}</b>" +
"<hr> View Assessor's Map: <a href=<b>www.acgov.org/MS/prop/index.aspx?PRINT_PARCEL=${APN}</b></a>" +
"<hr><img src='https://maps.googleapis.com/maps/api/streetview?size=270x150&location=${SitusAddress}&fov=120&pitch=-5&sensor=false&key=AIzfaNJyAak4_N4g0NaX-2LBqh2w3irnHZTtKJ2xKA'>");
//add features to map
var featureLayer = new FeatureLayer("https://services5.arcgis.com/ROBnTHSNjoZ2Wm1P/arcgis/rest/services/Parcels/FeatureServer/0", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["APN", "BOOK", "PAGE", "SitusAddress", "Imps", "YearBuilt"],
infoTemplate: template});
This what the site looks like when I click on a feature to bring up it's info including the APN:
If I paste the link text from here it takes me to this site:
But if I click it,it directs me here:
file:///C:/Users/jsobryan/OneDrive/Desktop/%3Cb
And I get the generic file not found message.
Oddly, when I paste it, the end of the b tag is converted to %3b
In the browser I see:
file:///C:/Users/jsobryan/OneDrive/Desktop/<b

You have a tag in the link and the link should start with "http://" to show that it is in a different domain.

Related

URL Paramters carried between pages - how to stop tel: also?

I have this really basic script that changes all the links on my wordpress site to preserve the url param - I use it on wordpress landing pages for my business
var queryString = new URL(window.location).search;
document.querySelectorAll("[href]").forEach(link => {
var current = link.href;
link.href = current + queryString;
});
E.g.
website.com/?location=Australia
All links on the page will carry over the parameter to whatever href link my visitor clicks
/book-online/?location=Australia
/request-a-callback/?location=Australia
However this is obviously changing all my href links, and is changing my tel: links with it.
Is there a way I can make it only change https://?
My tel: links look like this
tel:0293 12329?location=Australia
I have had this code copied and pasted for ages, I know absolutely nothing about javascript and no idea where I found the above code, I've just used it for ages and it works as a quick and easy way for me to track a users progress through my landing pages.
Perhaps you could only do this if tel: is not in the href?
var queryString = new URL(window.location).search;
document.querySelectorAll("[href]").forEach(link => {
var current = link.href;
if (!current.includes("tel:")) {
link.href = current + queryString;
}
});

java - edit url parameter of a page and show editing as a hyperlink in same page

i need java code to get a part from URL when reload a page and put it in hyperlink and show it in same page.
Example
get google drive file id from page url while reload:
http//example.com#https//drive.google.com/open?id=fileid
.
and add it to this hyperlink with new parameter:
http//docs.google.com/uc?id=fileid&export=download
you cant try javascript regular expressions
var url = window.location.href;
var parts = url.match(/id=(\w+)/);
console.log(parts[1]);

Google bookmarks script only saves about 1 in 5 links

I've been having this problem with the Google bookmarks "bookmarklet" button in Chrome for several years now: it does not reliably save URLs to https://www.google.com/bookmarks so I have to double-check every link I save. The form is invoked by clicking the Google Bookmark button in the Chrome bookmarks bar that is a javascript link that opens the form. The button comes from the bottom of the Google bookmarks page itself:
Google Bookmarks page
Google Bookmark button properties
Many links will not save unless I add a suffix such as #1 to the end of the URL, and even that is not a 100% effective workaround. For example, the URL http://jsbeautifier.org/ only saves if I append the #1 in the URL field: http://jsbeautifier.org/#1.
Google Bookmarks Form
I don't know if it's an issue with the javascript, encoding the URL, or an issue on Google's end they have never fixed. Here is the full javascript that comes directly from the button properties. I added the whitespace for readability:
javascript: (function() {
var a = window,
b = document,
c = encodeURIComponent,
d = a.open("https://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" + c(b.location) + "&title=" + c(b.title), "bkmk_popup", "left=" + ((a.screenX || a.screenLeft) + 10) + ",top=" + ((a.screenY || a.screenTop) + 10) + ",height=510px,width=550px,resizable=1,alwaysRaised=1");
a.setTimeout(function() {
d.focus()
}, 300)})();
Thanks in advance! :)
I have similar issue of not able to add a lot of https website into Google Bookmarks, especially those from Github or Google's Chrome Webstore. Sometimes if you change the https prefix to http, it will work, but not for all.
I guess the problem lies at the backend side, because it also fails when you try to add the URL in question directly at the Add bookmark page.
Seems Google deserted this product (originated from the time of Google Toolbar) and favors Google Chrome bookmark sync solution.

Keep UTM Source tracking in URL when user clicks on link

I run a news/publishing website where 95% of the traffic is coming from Facebook and from different Facebook fanpages.
I have set up UTM tracking through Google Analytics to track all links from different Fanpages to calculate how many visitors each page sents. This only tracks sessions when the user is sent to the website but when a user clicks on a link in the website such as another article the tracking is lost.
All users sent to the website have a UTM tracking code to the URL but when a user clicks on another link or article on the website the UTM tracking is removed from the URL therefore the tracking is lost for that user.
I want to track all pageviews from all users and sessions sent to the site.
I want the website to automatically have the UTM tracking in the URL when a user clicks on any link on the website.
For example, this is a link when a user is brought to the website:
http://99soccer.com/man-united-worried-as-rivals-man-city-are-poised-to-sign-their-transfer-target/?utm_source=slign-11&utm_medium=slign&utm_campaign=slign-11
If the user clicks on an article on the website this UTM tracking will disappear from the URL therefore not tracking the pageviews.
/?utm_source=slign-11&utm_medium=slign&utm_campaign=slign-11
Every user that will be sent to the website will be sent via referral and will have a utm source to track them but once you click on a link when you are on the website the tracking url (utm source) disappears. I want the tracking to stay there when you click on another link in the website.
var links = document.getElementsByTagName('a');
var utm = /(utm_source=.*)&(utm_medium=.*)&(utm_campaign=.*)/gi.exec(window.location.href);
for(var i=0;i<links.length;i++){
console.log(links[i].href = links[i].href + "?" + utm[0]);
}
This should do the trick.
I had this same problem and everywhere I searched, the solutions would suggest querying all <a> tags in the document on page load, loop over them, and apply the UTM parameters. This seems incomplete to me... what if the DOM gets updated with new links after page load? Seems using a click event handler would be the better route.
I came up with this and it seems to work for me. I don't know if it's foolproof though, so I'm open to improvements.
if (window.location.search.includes('utm_')) {
document.addEventListener('click', function(event){
// get the nearest anchor tag to where the user clicked (in case they clicked on something inside the anchor tag like an <img> or <span>
let aTag = event.target.closest('a');
if (aTag !== null) {
let urlParams = new URLSearchParams(window.location.search);
let aParams = new URLSearchParams(aTag.search);
// update the <a> tag's params with UTM params
for (let [key, value] of urlParams.entries()) {
// skip duplicates and only add new params that belong to UTM
if (! aParams.has(key) && key.includes('utm_')) {
aParams.append(key, value);
}
}
// reset the anchor's URL with all the query params added
aTag.href = aTag.href.split('?')[0] + '?' + aParams.toString();
}
});
}
There are better ways to get this data within GA. You can segment users with the initial referal source to your site and track the data that they have associated with them. I think this will accomplish what you want.
If for some reason I can't really think of you NEED to do this you could actively change all links on a page to include the UTM tag if a user loads the page with a UTM tag.
The rough structure of this:
1. Get the Document.url attribute
2. Logic check if it contains a UTM tag
3. If yes, add the same UTM tag to all links on the page
4. Add additional checks to remove UTM tags or other params those links might have as needed. Especially as the use of the & and ? in the url will need to be addressed.
You can manually set parameters for the session like this on the home page.
sessionStorage.setItem('utm_source', params.utm_source);
sessionStorage.setItem('utm_medium', params.utm_medium);
sessionStorage.setItem('utm_campaign', params.utm_campaign);
And then retrieve them on the contact page, probably to assign to a form field.
sessionStorage.getItem('itemName');

javascript generated links not working in ie8

there is a problem in ie8 related to links. html generated from javascript and display in the jquery ui dialog box but when I click on the link in it, it open link url in the same window (a tag has the targer=_blank set) and the url of link appended to the host url.
var clip_link = 'http://www.example.com/'+'c/'+id;
var thumb = 'http://www.example.com/235/45'+'/thumb.jpg';
$('#clip-share-popup .thumb').append(
'<img src="'+thumb+'" alt="clip thumb" />'
);
it is set after an ajax call
page url is
http://www.example.com/abcd.php#page/1/1
after click on the link the url become
http://www.example.comhttp//www.example.com/c/1234#
this doesn't happen in any other browser
You are probably not prefixing links with http://:
Google
Would take you to http://www.yourwebsite.com/whatever-page-you-are-on/www.google.com

Categories