120k views
0 votes
How can you display the current URL in a webpage using the writeln() method of the document object?

1) By using the href property of the window.location object
2) By using the write() method of the document object
3) By using the innerHTML property of the document object
4) By using the getElementById() method of the document object

User Tobint
by
7.6k points

1 Answer

3 votes

Final answer:

To display the current URL on a webpage, use the writeln() method with window.location.href, which writes the URL directly to the webpage upon loading.

Step-by-step explanation:

To display the current URL in a webpage using the writeln() method of the document object, you should use the href property of the window.location object. The document.writeln() method can take the current URL from window.location.href and write it directly to the web page when it is loaded.

Here is an example code snippet:

document.writeln("Current URL is: " + window.location.href);

This line of JavaScript code will output the string "Current URL is: " followed by the actual URL of the page where it is executed.

User Andreas Ka
by
7.9k points