Can I write a JavaScript code inside a url?

Here is a URL:

www.google.com

I want to write a JavaScript code inside the URL like :

alert(), document.write(), console.log() ..etc

If there no way tell me !.

Thanks.

>Solution :

No.

You can’t construct a URL that will execute JavaScript of your devising on an arbitrary web page.

If you could, it would be a major security problem as you could both exfiltrate any data you liked from the page and manipulate the DOM to mislead the people who opened the URL.

Sometimes a website has a server side flaw which causes data from the URL to be injected into the page. This is called an XSS security vulnerability and is an important thing for server-side developers to be aware of so they can avoid it. (It is also possible to create XSS issues using client-side JS, but it is less common).

Leave a Reply