Opening a new window using JavaScript for URL encoding

My ASP.NET 4.0 webform site includes a link that calls another page and passes URL parameters. The original link looks like this:

However, I realized I need to URL encode "anotherURI?param1=aaa&26param2=bbb" so it should look like this:

But when trying to enclose this in JavaScript for opening a popup window, it doesn't work. How can I re-encode the URL?

javascript:void(window.open('http://www.foo.com/foo.aspx?anotherURI?param1%3Daaa%26param2%3Dbbb', 'popup'))

Answer №1

Fix the URI:

INCORRECT:

CORRECT:

Example for multiple URIs: http://www.foo.com/foo.aspc?uri1=[encodedURI]&uri2=[encodedURI2]

To retrieve a value from a query string variable in asp.net:

Dim sUrl1 as String = request("VarName")
Dim sUrl2 as String = request("VarName")
Dim sUrl3 as String = request("VarName")

If you need to get the decoded URL from that particular variable:

Dim sDecodedUrl1 as String = Server.UrlDecode(sUrl1)
Dim sDecodedUrl2 as String = Server.UrlDecode(sUrl2)
Dim sDecodedUrl3 as String = Server.UrlDecode(sUrl3)

Answer №2

If you're looking to encode or decode text like PHP does, you can use the following JavaScript functions:

function url_encode(str) {
    str = (str + '').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). replace(/\)/g, '%29').replace(/\*/, '%2A').replace(/%20/g, '+');
}

function url_decode(str) {
    return decodeURIComponent((str + '').replace(/\+/, '%20'));
}

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

Make sure to place the <i> tag within the <li> tag at the bottom to automatically resize the height

Currently, I am working on customizing my menu design with a mix of bootstrap and font awesome CSS styles. It would be easier to demonstrate the issue on a live page. My main objectives are two-fold: I want to position the chevron icon at the bottom with ...

Tips for raising an Exception when a class has incorrect inheritance

I am working on an asp.net webforms application where every aspx.cs class must inherit from BasePage.cs, which in turn inherits from System.Web.UI.Page. My goal for page inheritance is as follows: class MyChildPage : BasePage : System.Web.UI.Page I am ...

OpenLayers' circular frames surrounding the icons

I am currently using openlayers and trying to implement a feature that creates a circle around the icons on the map. I have been referring to this example on Stack Overflow but unable to draw the circle successfully. Can someone please assist me with this? ...

Utilize Selenium to extract information from a webpage, including content that is dynamically generated through JavaScript

Currently, I am facing a dilemma: my desire is to extract information from a webpage (for example, this one) regarding the apps that are available, and then store this data into a database. In my quest to achieve this task, I have opted to use crawler4j t ...

Issues with asynchronous JavaScript and XML (AJAX) integration within JavaServer Pages (

I am encountering an issue with my code. When I run the project on localhost:\8081, everything works fine. However, when I upload it to a free host, it does not run properly. run not run Here is the AJAX code snippet: $(document).ready(function(){ ...

Is there a way in JavaScript to determine if a textarea contains text that is only one line long?

My aim is to modify the behavior of a textarea based on its content, specifically if it contains more than one line of text. The default setting for a textarea is to have enough height for 2 rows even when empty, which I want to change. I would like to f ...

Why is PHP unable to locate the index sent in the JSON data?

Why can't PHP seem to locate my index, myPostData? Utilizing jQuery/AJAX $('a').on("click", function(){ $.ajax({ type: "POST", url: "../image_view.php", data: {myPostData : {"lastName":"Sperrow", "firstName":"J ...

Adjust the text within the paragraph dynamically according to the option chosen in the drop-down menu using

I'm having trouble updating a paragraph in a letter based on the user's selection from a dropdown menu. I can't seem to figure it out. I don't know whether ng-show/hide or ng-options is the best approach for this. I feel completely los ...

Is it possible that event.returnvalue=false is causing issues in Firefox?

Currently, I am updating an outdated application to ensure it works seamlessly on Firefox. Since the original application does not utilize Jquery, I need to rely solely on Javascript for all my modifications. One of the tasks involves restricting input in ...

convert and transform XML data into JSON format

I have been working with nodejs-expressjs and I received a response in raw XML format. My goal is to convert this raw XML into either a JavaScript array or a JSON array so that I can extract the domain name along with its status. I want to display this inf ...

"Troubleshooting Problems with Scaling in the jQuery Mouse Wheel Plugin

I am currently utilizing this code in conjunction with the following plugin: mouse wheel $('#painter').on('mousewheel', function(e) { cp.scale(2, 2); var e0 = e.originalEvent, delta = e0.wheelDelta || -e0.de ...

Creating a TypeScript class with methods to export as an object

Just dipping my toes into Typescript and I've encountered a bit of a challenge. I have a generic class that looks like this: export class Sample { a: number; b: number; doSomething(): any { // return something } } My issue ari ...

Angular JS - Resolving issues with table headers

I've been working on fixing the headers of a table and have tried multiple solutions I found online, but nothing seems to be effective for me. Here's my current code: <div class="report-container"> <div class="row"> <d ...

Add the hue value from Hue into the Chromajs HSL state value

My objective is to dynamically change the background color of a div based on user input. I plan to assign the user's input as the value of the state key hue, and then set another state key called color to hold the HSL representation of the hue using C ...

Issue with typography upon initial page load

Hey everyone! I recently completed a crash course in html, css, and javascript within just one month. However, I encountered an issue while using canvas to draw text with a custom font. The font didn't load the first time I ran the code, but strangely ...

Receiving "Illegal Invocation" error when attempting to submit form using ajax

I am attempting to submit a form using ajax, and here is the form code: <form class="form-vertical" method="POST" id="request-form" action="/post_handler?request=add_data" enctype="multipart/form-data"> <div class="form-group"> <label ...

Why is it that the HttpClient constructor in Angular doesn't require parameters when instantiated through the constructor of another class, but does when instantiated via the 'new' keyword?

I am trying to create a static method for instantiating an object of a class, but I have encountered a problem. import { HttpClient } from '@angular/common/http'; export MyClass { // Case 1 public static init(): MyClass { return this(new ...

JQuery: The .not() function does not effectively filter out items from the collection

I want to iterate through multiple span elements and extract the text from them. However, I need to skip any text that is within elements with a specific class. Here's an example: <html> <head> <script src="http://code.jquer ...

Comparison of Node.js and Express.js APIs for handling responses

Both Node.js and Express.js have their own unique response APIs. Interestingly, there are some similarities between the two, such as: Node.js: response.write(chunk[, encoding][, callback]) Express.js: res.attachment([filename]) res.download(path [, ...

In JavaScript, if you check for the existence of a key in an object, it

Recently, I ran into an issue with an undefined error when trying to access a value in a JavaScript object key. I retrieved arrays of objects using the mongoose.find().exec() callback and then checked each object for a specific key. Here is an example obj ...