Google information window: clicking a link will trigger a page refresh

I am currently running some tests for a web page that I need to design. As part of this process, I have written some code to add markers on a map and include an Info Window for each marker with specific information:

function placeLocationMarker(latitude, longitude, icon_path, location_name, website_url)
{
    //generate marker's info
    var contentString = '<div id="content"><div id="siteNotice">' +
    '</div><div id="bodyContent"><h4 id="firstHeading" class="firstHeading">' +  location_name + '</h4>' +
        '<a href=""' + website_url + ' style="text-decoration:none"><b>Website</b></a></div></div>';
    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });

    var markerPosition = new google.maps.LatLng(latitude, longitude);
    var marker = new google.maps.Marker
    (
        {
            position: markerPosition,
            map: map,
            animation: google.maps.Animation.DROP,
            icon: icon_path,
            title: location_name
        }
    );

    marker.addListener('click', function() {
        infowindow.open(map, marker);
    });

    markers.push(marker);
}

This function is called for each marker that needs to be added to the map:

for(var j = 0; j<interest_points.length; j++)
    {
        placeLocationMarker(
            interest_points[j].Lat,
            interest_points[j].Lon,
            "http://gmaps-samples.googlecode.com/svn/trunk/markers/orange/blank.png",
            interest_points[j].Name,
            interest_points[j].Wikipedia
        );
    }

The resulting info window correctly displays all the information, including the URL. However, when I click on the URL, my entire page containing the map simply reloads. On the Google Info Window example page (Google Info Window), clicking a link loads a new page replacing the map. This behavior is not ideal as the loaded page cannot be scrolled and only a portion is visible based on the original map size. I would prefer it if the user could click on the link inside the Info Window and have it open in a new tab to display the loaded page.

Any suggestions or ideas? Thank you.

Answer №1

Upon initial inspection, my assessment is that the code '<a href=""' + url + ' needs to be corrected to '<a href="' + url + '"' in order for your URL to be properly placed within the href attribute.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to extract the date value from an HTML date tag without using a datepicker

Utilizing Intel's app framework means there is no .datepicker method available. The following code snippet generates the date widget within my app: <label for="startdate">Start Date:</label> <input type="date" name="startdate" id="star ...

What is the best way to flip cards with the onClick event in JavaScript?

My cards are currently facing down with the code* provided. What steps should I take to flip them face up using onClick functions? Furthermore, how can I store the IDs in an Array and use them to retrieve images from my image collection? HTML <table s ...

What is the functionality of the filterBy method in Vue.js 1.x?

Looking to create a filter for my app similar to the filterBY Vue.js feature on older versions... Currently working on a Computed Property to generate an array containing objects that match a specified string variable... However, my goal is to create a re ...

Upon clicking the button, provide the client with the Cloudinary link

In my Next.js project, I am using Cloudinary to generate secure URLs for images. The URL is stored in the variable result.secure_url within my app/page.js file. The button functionality is defined in app/components/Cloudinary.js and imported into app/pag ...

Exploring ways to implement identical 'if' conditions across various controllers in AngularJS

Is there a way to avoid repeating the if condition in multiple controllers? How can I simplify this process? MainController.js : $scope.responseData.forEach(function(card) { switch (card.Category) { case 'Apple': conso ...

JQuery script fails to load in the head section while dynamically generating an HTML page with JavaScript

Using JavaScript, I have created a new window dynamically and added some HTML code to it. However, when I try to insert a script link into the HTML head, it fails to load when the window is open. <script type="text/javascript"> function newWindo ...

Toggle Button Control

In my PHP file, I have a submit button for the form coded like this: <input type="submit" name="submit" value="submit" disabled="true" /> Next, I initiate an asynchronous request using a request object, document.getElementById("username").onblur= ...

Steps for creating a new tab and refreshing the address bar with a different URL without having to reload the current page

I'm trying to create a functionality on my page where clicking a button will open a new tab with a modified URL, all without reloading the current page. Below is the code that I'm using when the button is clicked: function changeUrl(){ var pri ...

Retrieving results from a Node.js application that utilizes multithreading

A new function called diversify() has been developed to execute an expensive function f() in parallel on all the cores of the machine in which it is being deployed. Additionally, a mechanism has been implemented so that when f() returns a value on one core ...

Ensuring proper validation of sinon stub parameters in TypeScript

One of the unit tests in my code is responsible for checking the function arguments. it('Should retrieve product from the database', () => { stub(ProductModel, 'findById').returns({ lean: stub().returns({ total: 12 }), }); ...

Error encountered in jQuery validation: Uncaught TypeError - $(...) ""valid is not a function" is displayed with proper references and order

When I try to call a function, I keep getting an error message that says "Uncaught TypeError: $(...).valid is not a function"... JS $('input[data-val=true]').on('blur', function() { $(this).valid(); }); HTML <div class="col-x ...

.load() not triggering for images that are not in the cache - jquery

In Safari and Opera, the callback function of .load doesn't wait for uncached images to be fully loaded. With cached images, it works perfectly fine. The code may seem a little complicated, but I'll do my best to simplify it... So, here is my J ...

Transferring JSON information from Express to Backbone

I have developed a basic Backbone application and am trying to integrate JSON data from a MYSQL database using an Express server. However, when I make a GET request with Express to fetch data for Backbone, the html template in Backbone disappears, leaving ...

Generate a distinct identifier for each element in the array by assigning a new key derived from the object's index within the array

I am attempting to give each object in the array a new key with a unique id based on its index within the array. Upon clicking a button, the following code runs: this.setState({ testStatus: "running", clicked: true }); tests.map(test => { ...

Encountering a problem with AngularJS when attempting to access an array and display an alert message

While working with Angular, I encountered an issue in trying to access content stored within an array. Upon reviewing the code, console.log(JSON.stringify($scope.lineItems)) was returning [[]]. However, when inspecting or setting a breakpoint on this line ...

Handling error reporting using JSON in jQuery AJAX post success

UPDATE: I have resolved the PHP errors mentioned in previous Answers, however, the issue still persists. I am attempting to implement an error message display in case of a failed POST request and a success message for successfully completed requests. Curr ...

A guide on transferring a Vue component to a custom local library

After successfully creating components using template syntax (*vue files), I decided to move common components to a library. The component from the library (common/src/component/VButton): <template> <button ... </button> </templat ...

Changing the appearance of a website by applying various stylesheets based on the size of the browser window in

After implementing the code below to switch between stylesheets based on browser height, I encountered a small issue. The code works perfectly when the page first loads or when the window is resized and then refreshed. However, I'm curious if there&ap ...

Vue JS - Issue with data reactivity not being maintained

Currently, I have implemented a pagination indicator that displays the number of results on each page. For instance, page 1 shows '1-5' and page 2 shows '6-10 out of 50 results', and so on. The logic for updating the results seems to b ...

MongoDB does not return any results for the query and returns

I am facing an issue while trying to retrieve information from my mongodb database. Despite successfully fetching data from the "users" collection, I keep getting an empty object for other collections. var mongoose = require('mongoose'); var Sch ...